This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| code:graphql:confrence2020 [2020/03/30 16:38] – created ltsover9000 | code:graphql:confrence2020 [2020/03/30 23:25] (current) – ltsover9000 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Notes ====== | ====== Notes ====== | ||
| - | |||
| - | |||
| * One endpoint `/graphql` | * One endpoint `/graphql` | ||
| * Query | * Query | ||
| Line 9: | Line 7: | ||
| * Enums are useful | * Enums are useful | ||
| + | < | ||
| + | enum PhotoCategory { | ||
| + | PORTRAIT | ||
| + | ACTION | ||
| + | TEST | ||
| + | } | ||
| + | </ | ||
| Aliasing a query: | Aliasing a query: | ||
| Line 17: | Line 22: | ||
| </ | </ | ||
| + | Neat link | ||
| + | |||
| + | * https:// | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | Handling multiple behaviours for a single endpoint | ||
| + | |||
| + | * array of options, filters... handle on the server | ||
| + | |||
| + | |||
| + | Dont forget you can put two queries in one: | ||
| + | |||
| + | < | ||
| + | query{ | ||
| + | query1{...} | ||
| + | query2{...} | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | graphql scalar type | ||
| + | |||
| + | * Int | ||
| + | * Float | ||
| + | * String | ||
| + | * Boolean | ||
| + | * ID | ||
| + | |||
| + | Nullable | ||
| + | |||
| + | < | ||
| + | name: String! | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | description: | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | Nullable list of nullable values | ||
| + | < | ||
| + | photos: [Photo] | ||
| + | </ | ||
| + | |||
| + | non-Nullable list of nullable values | ||
| + | < | ||
| + | photos: [Photo]! | ||
| + | </ | ||
| + | |||
| + | non-Nullable list of non-nullable values | ||
| + | < | ||
| + | photos: [Photo!]! | ||
| + | </ | ||
| + | |||
| + | |||
| + | Mutations | ||
| + | * ~should~ always return atleast something | ||
| + | |||
| + | < | ||
| + | type mutation{ | ||
| + | get(): Boolean! | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Custom Scalar ===== | ||
| + | |||
| + | Things that arent gonna be a custom scalar, it will probably be an custom ENUM | ||
| + | |||
| + | < | ||
| + | |||
| + | scalar DateTime | ||
| + | |||
| + | type Photo { | ||
| + | created: DateTime! | ||
| + | updated: DateTime! | ||
| + | }</ | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | |||
| + | ===== MOCK: TRUE -- Super useful | ||
| + | const server = new ApolloServer({ | ||
| + | typeDefs, | ||
| + | resolvers, | ||
| + | mocks: true // TODO -- super handy | ||
| + | }); | ||
| + | |||
| + | |||
| + | |||
| + | ===== Documentation ===== | ||
| + | |||
| + | |||
| + | < | ||
| + | """ | ||
| + | Triple double-quote for the type. This is doc for the type | ||
| + | """ | ||
| + | type X { | ||
| + | " | ||
| + | field: ID! | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Interface and misc ===== | ||
| + | |||
| + | returns the typename for the field | ||
| + | < | ||
| + | |||
| + | |||
| + | < | ||
| + | < | ||
| + | type pet{ | ||
| + | id | ||
| + | name | ||
| + | weight | ||
| + | ...on Cat{ | ||
| + | curious | ||
| + | } | ||
| + | ...on Stingray{ | ||
| + | stingy | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== resolvers ===== | ||
| + | |||
| + | resolvers are used to get data wherever it is | ||
| + | |||
| + | |||
| + | ===== Maybe give some info on ApolloClient ===== | ||
| + | Apollo dev tool (chrome + firefox addon) | ||
| + | * shows schema + graphiql | ||
| + | * displays cached data | ||
| + | * root query | ||
| + | How are you supposed to use subscriptions? | ||