Data passed to schema
's resolver
/field
.
Argument
values can be hardcoded as a value or passed via GraphQL input
variable.# schema definition type Query { resources: [Resource!]! resource(format: DataFormat!): Resource! } # client query query GetResource { resource(format: "jpeg") { id data } }
resources
field returns array of Resource
type data
resource
field returns object of Resource
type after taking in format
argument
Resolvers
consumes the input
value and executes functioninput
argument
/input
allows user to narrow down the data returned.
Query
fields are an all-or-nothing
return.# schema definition field resource(format: DataFormat!): Resource!
resource
is the field
nameformat
is the argument
nameDataFormat
would be the argument's data type
!
makes it non-nullable
required argumenterror
when other types are passedResource
would be the return data type on the field
!
makes it non-nullable
required return typeinput
type can be a scalar
or an object.
# server/schema.graphql example of object input input SearchListingsInput { checkInDate: String! checkOutDate: String! numOfBeds: Int page: Int limit: Int sortBy: SortByCriteria # enum type } type Query { searchListings(criteria: SearchListingsInput): [Listing]! }
Client
using input
The argument
on the client
query and the schema
can be named anything.
field name
on the schema
# query query getUserPosts($userId: ID!, $postLimit: Int!) { user(id: $userId) { name posts(limit: $postLimit) { title content } } } # schema # Root query is identical schema { query: Query } # Define the root query type type Query { user(id: ID!): User } # Define the custom types type User { id: ID! name: String! posts(limit: Int!): [Post!]! } type Post { id: ID! title: String! content: String! }