From 8a5e473117a13a7eec7c625ea2d3e6a605f4afaa Mon Sep 17 00:00:00 2001 From: Koleok Date: Tue, 7 Feb 2017 01:34:40 -0500 Subject: [PATCH 1/3] Add markdown port of blog text/image/docs references --- 2017-02-07/README.md | 234 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 234 insertions(+) create mode 100644 2017-02-07/README.md diff --git a/2017-02-07/README.md b/2017-02-07/README.md new file mode 100644 index 0000000..cc92d4a --- /dev/null +++ b/2017-02-07/README.md @@ -0,0 +1,234 @@ +# GraphQL Schema Language Cheat Sheet +The definitive guide to express your GraphQL schema succinctly + +_Last updated: 2017-01-28_ + +_Prepared by: Hafiz Ismail / @sogko_ + +## What is GraphQL Schema Language? + +It is a shorthand notation to succinctly express the basic shape of your GraphQL schema and its type system. + +--- + +## What does it look like? + +Below is an example of a typical GraphQL schema expressed in shorthand. + +```graphql +# define E#ntity interface +interface Entity { + id: ID! + name: String +} + +## define custom Url Scalar +scalar Url + +## User type implements Entity interface +type User implements Entity { + id: ID! + name: String + age: Int + balance: Float + is_active: Boolean + friends: [User]! + homepage: Url +} + +## root Query type +type Query { + me: User + friends(limit: Int = 10): [User]! +} + +## custom complex input type +input ListUsersInput { + limit: Int + since_id: ID +} + +## root mutation type +type Mutation { + users(params: ListUsersInput): [User]! +} + +## GraphQL root schema type +schema { + query: Root + mutation: Mutation + subscription: ... +} +``` + +## Schema + +| keyword | definition | +|----------------|-----------------------------------------| +| `schema` | GraphQL schema definition | +| `query` | A read-only fetch operation | +| `mutation` | A write followed by a fetch operation | +| `subscription` | A subscription operation (experimental) | + +## [Built-in Scalar Types](http://graphql.org/learn/schema/#scalar-types) + +| keyword | definition | +|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `Int` | A signed 32‐bit integer | +| `Float` | A signed double-precision floating-point value | +| `String` | A UTF‐8 character sequence | +| `Boolean` | `true` or `false` | +| `ID` | The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache. The ID type is serialized in the same way as a String; however, defining it as an ID signifies that it is not intended to be human‐readable. | + +## Type Definitions + +| keyword | definition | +|-------------|---------------------------------------------------------------------------------------------------------| +| `scalar` | Represent the leaves of the query (values of fields) | +| `type` | Simple object with fields | +| `interface` | Abstract type that includes a certain set of fields that a type must include to implement the interface | +| `union` | Similar to interfaces, but without specifing common fields between types | +| `enum` | A special kind of scalar that is restricted to a particular set of allowed values | +| `input` | Represent non-scalars for arguments | + +## Type Modifiers + +| keyword | definition | +|--------------|-------------------------------------------| +| `String` | Nullable string | +| `String!` | Non-nullable string | +| `[String]` | List of nullable strings | +| `[String]!` | Non-nullable list of nullable strings | +| `[String!]!` | Non-nullable list of non-nullable strings | + +## Input Arguments + +### Basic input + +```graphql +type Root { + users(limit: Int): [User]! +} +``` + +### Input with default value + +```graphql +type Root { + users(limit: Int = 10): [User] +} +``` + +### Input with multiple args + +```graphql +type Root { + users(limit: Int, sort: String): [User] +} +``` + +### Input with multiple args and default values + +```graphql +type Root { + users(limit: Int = 10, sort: String): [User] +} + +## or + +type Root { + users(limit: Int, sort: String = "asc" ): [User] +} + +## or + +type Root { + users(limit: Int = 10, sort: String = "asc" ): [User] +} +``` + +## Input Types + +```graphql +input ListUsersInput { + limit: Int + since_id: ID +} + +type Mutation { + users(params: ListUsersInput): [Users]! +} +``` + +## Custom Scalar + +```graphql +scalar Url + +type User { + name: String + homepage: Url +} +``` + +## Interfaces + +Object implementing one or more interfaces +```graphql +interface Foo { + is_foo: Boolean +} + +interface Goo { + is_goo: Boolean +} + +type Bar implements Foo { + is_foo: Boolean + is_bar: Boolean +} + +type Bar implements Foo, Goo { + is_foo: Boolean + is_goo: Boolean + is_bar: Boolean +} +``` + +## Unions + +Union of one or more objects + +```graphql +type Foo { + name: String +} + +type Bar { + is_bar: String +} + +union SingleUnion = Foo +union MultipleUnion = Foo | Bar + +type Root { + single: SingleUnion + multiple: MultipleUnion +} +``` + +## Enums + +```graphql +enum USER_STATE { + NOT_FOUND + ACTIVE + INACTIVE + SUSPENDED +} + +type Root { + stateForUser(userID: ID!): USER_STATE! + users(state: USER_STATE, limit: Int = 10): [User] +} +``` From 279d4f488478d0c1ec9f23a103933d5097dc9991 Mon Sep 17 00:00:00 2001 From: Koleok Date: Tue, 7 Feb 2017 01:40:59 -0500 Subject: [PATCH 2/3] Add links --- 2017-02-07/README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/2017-02-07/README.md b/2017-02-07/README.md index cc92d4a..99001b3 100644 --- a/2017-02-07/README.md +++ b/2017-02-07/README.md @@ -5,7 +5,7 @@ _Last updated: 2017-01-28_ _Prepared by: Hafiz Ismail / @sogko_ -## What is GraphQL Schema Language? +## What is GraphQL [Schema Language](http://graphql.org/learn/schema/#type-language)? It is a shorthand notation to succinctly express the basic shape of your GraphQL schema and its type system. @@ -85,13 +85,13 @@ schema { | keyword | definition | |-------------|---------------------------------------------------------------------------------------------------------| | `scalar` | Represent the leaves of the query (values of fields) | -| `type` | Simple object with fields | +| `type` | Simple [object](http://graphql.org/learn/schema/#object-types-and-fields) with fields | | `interface` | Abstract type that includes a certain set of fields that a type must include to implement the interface | | `union` | Similar to interfaces, but without specifing common fields between types | | `enum` | A special kind of scalar that is restricted to a particular set of allowed values | | `input` | Represent non-scalars for arguments | -## Type Modifiers +## [Type Modifiers](http://graphql.org/learn/schema/#lists-and-non-null) | keyword | definition | |--------------|-------------------------------------------| @@ -101,12 +101,12 @@ schema { | `[String]!` | Non-nullable list of nullable strings | | `[String!]!` | Non-nullable list of non-nullable strings | -## Input Arguments +## [Input Arguments](http://graphql.org/learn/schema/#arguments) ### Basic input ```graphql -type Root { +type Query { users(limit: Int): [User]! } ``` @@ -114,7 +114,7 @@ type Root { ### Input with default value ```graphql -type Root { +type Query { users(limit: Int = 10): [User] } ``` @@ -122,7 +122,7 @@ type Root { ### Input with multiple args ```graphql -type Root { +type Query { users(limit: Int, sort: String): [User] } ``` @@ -130,24 +130,24 @@ type Root { ### Input with multiple args and default values ```graphql -type Root { +type Query { users(limit: Int = 10, sort: String): [User] } ## or -type Root { +type Query { users(limit: Int, sort: String = "asc" ): [User] } ## or -type Root { +type Query { users(limit: Int = 10, sort: String = "asc" ): [User] } ``` -## Input Types +## [Input Types](http://graphql.org/learn/schema/#input-types) ```graphql input ListUsersInput { @@ -171,7 +171,7 @@ type User { } ``` -## Interfaces +## [Interfaces](http://graphql.org/learn/schema/#interfaces) Object implementing one or more interfaces ```graphql @@ -195,7 +195,7 @@ type Bar implements Foo, Goo { } ``` -## Unions +## [Unions](http://graphql.org/learn/schema/#union-types) Union of one or more objects @@ -217,7 +217,7 @@ type Root { } ``` -## Enums +## [Enums](http://graphql.org/learn/schema/#enumeration-types) ```graphql enum USER_STATE { From ef4d6f7c8e2d318fb2bd0c554626ad6ee7191954 Mon Sep 17 00:00:00 2001 From: Koleok Date: Tue, 7 Feb 2017 01:49:04 -0500 Subject: [PATCH 3/3] Add extra link for custom scalar heading --- 2017-02-07/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2017-02-07/README.md b/2017-02-07/README.md index 99001b3..f9bb394 100644 --- a/2017-02-07/README.md +++ b/2017-02-07/README.md @@ -160,7 +160,7 @@ type Mutation { } ``` -## Custom Scalar +## [Custom Scalar](http://graphql.org/learn/schema/#scalar-types) ```graphql scalar Url