https://graphql.schule/api2022
https://graphql.schule/install
https://nilshartmann.net / @nilshartmann
Freiberuflicher Software-Entwickler, Berater und Trainer aus Hamburg
Java | JavaScript, TypeScript | React | GraphQL
query { story(storyId: 5) { id title writtenBy { id user { name } } } }
query NewestStory { story { id title } }
fragment BaseMember on Member { id joined user { is username } } query { story { writtenBy { ...BaseMember } reactions { givenBy { ...BaseMember } } } }
mutation addComment (input: { storyId: "1", content: "..." }) { ...on AddCommentSuccessPayload { newComment { id } } ...on AddCommentFailurePayload { errorMessage } }
query { node(id: "...") { id createdAt ...on Story { title body } ...on Comment { content } } }
query ($storyId: ID!) { story(id: $storyId) { id title body } }
type Story { id: ID! title: String! body: String! }
""" A `Story` is the main object in our service. """ type Story { """Identifies this object""" id: ID! # todo: implement new tags-field (PROJ-666) }
type Member { id: ID! username: String! # no exclamation mark: can be null likes: Int amount: Float! activeMember: Boolean }
enum ReactionType { like, laugh, thumbUp }
type Member { # ... } type Comment { # ... } type Story { """Reference to the Member that has written this Story""" writtenBy: Member! comments: [Comment!]! }
type Story { # Mandatory argument maxLength, defaults to 20 # if not specified by the client excerpt(maxLength: Int! = 20): String! }
type Query { """Returns a List of all stories""" stories: [Story!]! """Returns a story by its ID or null""" story(id: ID!): Story } type Mutation { addComment(storyId: ID!, memberId: ID!, content: String!): Comment! }
input AddCommentInput { storyId: ID! memberId: ID! content: String! } type Mutation { addComment(input: AddCommentInput!): Comment! }
type AddCommentSuccess { newComment: Comment! } type AddCommentFailed { errorMessage: String! } union AddCommentResult = AddCommentSuccess | AddCommentFailed type Mutation { addComment(input: AddCommentInput!): AddCommentResult! }
interface Node { id: ID! } type Story implements Node { id: ID! # Field defined in Node-Interface title: String! # additional Story fields } type Comment implements Node { id: ID! content: String! } type User { id: ID! email: String } type Query { # Returns either Story or Comment, but not User node(id: ID!): Node }
type Query { # Ausgangspunkt getStoryById(id: ID!): Story }
type Query { getStoryById(id: ID!): Story # Neues Feld, beeinträchtigt bestehenden Client nicht stories: [Story!]! }
type Query { getStoryById(id: ID!): Story @deprecated("Use story instead") story(id: ID!): Story stories: [Story!]! }
# story.graphqls extend type Query { story(id: ID!): Story } # comment.graphqls extend type Query { comment(id: ID): Comment }
query { stories { id title body writtenBy { id profileImage } } }
query { story(storyId: 1) { id title body writtenBy { id profileImage } } }
query { story(storyId: 1) { id writtenBy { id # Hier sollten nun Daten kommen: user { id name email } } } }
query { stories { writtenBy { user { id email } } } }
Wenn ihr noch Fragen habt, könnt ihr mich erreichen:
nils@nilshartmann.net
https://nilshartmann.net
Xing
Twitter: @nilshartmann