GraphQL Samples

MD
S
Markdown

Introduction to writing GraphQL Queries. An in-browser IDE for exploring GraphQL: https://github.com/graphql/graphiql

Glossary of terms

  • "Site" is a type with a couple of fields available to it
  • An Object is a Node in a Graph

Complete Example

schema {
  query: RootQueryType
  mutation: RootMutationType
}

type RootQueryType {
  currentUser: CurrentUser
  billing: Billing
}

type RootMutationType {
  registerUser(email: String!, invitationToken: String, password: String!): CurrentUser
  registerCompany(name: String!): Company
  resetPassword(password: String!, resetPasswordToken: String!): CurrentUser
  login(email: String!, password: String!): CurrentUser
  logout: CurrentUser
  updateBilling(input: UpdateBillingInput!): Billing
}

type CurrentUser {
  id: ID
  authToken: String
  firstName: String
  lastName: String
  email: String
  mobile: String
  isOwner: Boolean
  company: Company
}

type Company {
  id: ID
  name: String
}

type Billing {
  trialDaysLeft: Int
  plan: BillingPlan
  card: Card
  nextPaymentDue: String
}

enum BillingPlan {
  FREE
  SOLO
  TEAM
}

type Card {
  lastFourDigits: String
  type: String
}

Mapping between the Schema and JSON

{
  site {
    siteMetadata {
      title
      description
    }
    port
    host
    buildTime
  }
}

JSON

{
  "data": {
    "site": {
      "siteMetadata": {
        "title": "dummy title sample",
        "description": "dummy description sample"
      },
      "port":"8080",
      "host":"127.0.0.1",
      "buildTime":"2018-09-10"
    }
  }
}

Created on 9/17/2018