User Tools

Site Tools


code:graphql:confrence2020

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
code:graphql:confrence2020 [2020/03/30 16:44] – ltsover9000code: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 
  
 +<code>
 +enum PhotoCategory {
 +  PORTRAIT
 +  ACTION
 +  TEST
 +}
 +</code>
  
 Aliasing a query: Aliasing a query:
Line 23: Line 28:
  
  
 +
 +Handling multiple behaviours for a single endpoint
 +
 +  * array of options, filters... handle on the server 
 +
 +
 +Dont forget you can put two queries in one: 
 +
 +<code>
 +query{
 +  query1{...}
 +  query2{...}
 +}
 +</code>
 +
 +graphql scalar type
 +
 +  * Int 
 +  * Float 
 +  * String
 +  * Boolean
 +  * ID
 +
 +Nullable  vs non nullable
 +
 +<code>
 +name: String!
 +</code>
 +
 +<code>
 +description: String
 +</code>
 +
 +
 +
 +Nullable list of nullable values
 +<code>
 +photos: [Photo]
 +</code>
 +
 +non-Nullable list of nullable values
 +<code>
 +photos: [Photo]!
 +</code>
 +
 +non-Nullable list of non-nullable values
 +<code>
 +photos: [Photo!]!
 +</code>
 +
 +
 +Mutations
 +  * ~should~ always return atleast something
 +
 +<code>
 +type mutation{
 +  get(): Boolean!
 +}
 +</code>
 +
 +
 +===== Custom Scalar =====
 +
 +Things that arent gonna be a custom scalar, it will probably be an custom ENUM 
 +
 +<code>
 +
 +scalar DateTime
 +
 +type Photo {
 +  created: DateTime!
 +  updated: DateTime!
 +}</code>
 +
 +[[https://raw.githubusercontent.com/sogko/graphql-shorthand-notation-cheat-sheet/master/graphql-shorthand-notation-cheat-sheet.png]]
 +
 +
 +===== MOCK: TRUE -- Super useful  =====
 +const server = new ApolloServer({
 +    typeDefs,
 +    resolvers,
 +    mocks: true // TODO -- super handy
 +});
 +
 +
 +
 +===== Documentation =====
 +
 +
 +<code>
 +"""
 +Triple double-quote for the type. This is doc for the type
 +"""
 +type X {
 +  "Single double-quote for the field"
 +  field: ID!
 +}
 +</code>
 +
 +
 +===== Interface and misc =====
 +
 +returns the typename for the field
 +<code>__typename</code>
 +
 +
 +<code>...on </code>
 +<code>
 +type pet{
 +  id
 +  name
 +  weight
 +  ...on Cat{
 +    curious
 +  }
 +  ...on Stingray{
 +    stingy
 +  }
 +}
 +</code>
 +
 +
 +===== 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? should they return data or no? 
code/graphql/confrence2020.1585586662.txt.gz · Last modified: by ltsover9000