Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.

Latest commit

 

History

History
59 lines (48 loc) · 873 Bytes

server-cheatsheet.md

File metadata and controls

59 lines (48 loc) · 873 Bytes

Server cheat sheet

Default types

  • Int
  • Float
  • String
  • Boolean
  • ID

Types

type Person {
  id: ID! # Not nullable
  name: String # Nullable
  age: Int
  weight: Float
  isOnline: Boolean
  posts: [Post!]! # Not nullable (but empty list is fine)
}

type Post {
  id: ID!
  slug: String!
  text: String!
}

type Query {
  allPersons: [Person!]!
  personById(id: ID!): Person
  allPosts: [Post!]!
  postBySlug(slug: String!): Post
}

type Mutation {
  createPost(from: Person!, slug: String!, text: String!): Post!
}

Resolver signature

(obj, args, context, info) => result;

Resolvers

const resolvers = {
  Query: {
    personById: (obj, args) => API.getPersonById(args.id),
  },
  Person: {
    posts: obj => API.getPostsByPersonId(obj.id),
    // Note that all other fields are resolved by default
  },
};