Sie sind auf Seite 1von 1

Input Arguments Interfaces

GraphQL Schema Language Cheat Sheet Basic Input Object implementing one or more Interfaces
The definitive guide to express your GraphQL schema succinctly
Last updated: 28 January 2017 type Query { interface Foo {
Prepared by: Hafiz Ismail / @sogko users(limit: Int): [User] is_foo: Boolean
} }
interface Goo {
What is GraphQL Schema Language? Schema Input with default value is_goo: Boolean
It is a shorthand notation to succinctly express the }
basic shape of your GraphQL schema and its type schema GraphQL schema definition
type Query { type Bar implements Foo {
system. query A read-only fetch operation users(limit: Int = 10): [User] is_foo: Boolean

mutation A write followed by fetch operation } is_bar: Boolean


What does it look like? }
subscription A subscription operation
Below is an example of a typical GraphQL schema Input with multiple arguments type Baz implements Foo, Goo {
expressed in shorthand. (experimental)
is_foo: Boolean

type Query { is_goo: Boolean


# define Entity interface users(limit: Int, sort: String): [User] is_baz: Boolean
interface Entity {
Built-in Scalar Types } }
id: ID!
name: String
} Int Int Input with multiple arguments and default values Unions
# define custom Url scalar Float Float
scalar Url type Query { Union of one or more Objects
String String users(limit: Int = 10, sort: String): [User]
# User type implements Entity interface Boolean
}
Boolean type Foo {
type User implements Entity {
id: ID! ID ID type Query { name: String
name: String users(limit: Int, sort: String = "asc"): [User] }
age: Int }
type Bar {
balance: Float
is_active: Boolean type Query { is_bar: String
friends: [User]! Type Definitions users(limit: Int = 10, sort: String = "asc"): [User] }
homepage: Url }
} union SingleUnion = Foo
scalar Scalar Type
union MultipleUnion = Foo | Bar
# root Query type type Object Type Input Types type Root {
type Query {
me: User interface Interface Type single: SingleUnion
friends(limit: Int = 10): [User]! input ListUsersInput {
multiple: MultipleUnion
union Union Type
} limit: Int
}
enum Enum Type since_id: ID
# custom complex input type
input ListUsersInput { input Input Object Type }
Unions
Enums
limit: Int type Mutation {
since_id: ID
users(params: ListUsersInput): [User]! enum USER_STATE {
}
} NOT_FOUND
# root mutation type Type Modifiers ACTIVE
type Mutation {
users(params: ListUsersInput): [User]! Custom Scalars INACTIVE
String Nullable String
} SUSPENDED
String! Non-null String scalar Url }
# GraphQL root schema type
schema { [String] List of nullable Strings type User { type Root {
query: Query name: String stateForUser(userID: ID!): USER_STATE!
[String]! Non-null list of nullable Strings
mutation: Mutation
homepage: Url users(state: USER_STATE, limit: Int = 10): [User]
subscription: ... [String!]! Non-null list of non-null Strings
} } }

Das könnte Ihnen auch gefallen