Skip to content

Instantly share code, notes, and snippets.

@danielrearden
Last active June 30, 2020 04:24
Show Gist options
  • Save danielrearden/96499320d66f00b1cb8701c0e2c8b9a9 to your computer and use it in GitHub Desktop.
Save danielrearden/96499320d66f00b1cb8701c0e2c8b9a9 to your computer and use it in GitHub Desktop.
Schema Patterns by Provider

This document summarizes the schema patterns employed by popular GraphQL APIs, frameworks and service providers. The shown types maybe be incomplete and not completely correct with regard to nullability or type names; however, they should provide a general idea of the capabilities of each provider.

Where appropriate, the shown types illustrate basic features like filtering, sorting and pagination. Providers may expose additional capabilities that are not illustrated in this document.

Find One

AWS Amplify
type Query {
  getPost(id: ID!): Post
}
Hasura
type Query {
  post_by_pk(id: ID!) Post
}
PostGraphile
type Query {
  post(id: ID!): Post
}

Find Many

AWS Amplify **Note:** Generated queries do not include any "sort" parameter. Sort order is static and determined by generated indexes.
type Query {
  listPosts(filter: PostFilterInput, limit: Int, nextToken: String): ModelPostConnection
}

input PostFilterInput {
  id: ModelIDFilterInput
  title: StringFilterInput
  and: [PostFilterInput]
  or: [PostFilterInput]
  not: PostFilterInput
}

input StringFilterInput {
  ne: String
  eq: String
  le: String
  lt: String
  ge: String
  gt: String
  contains: String
  notContains: String
  between: [String]
  beginsWith: String
}

type ModelPostConnection {
  items: [Post]
  nextToken: String
}
Hasura
type Query {
  post(
    where: post_bool_exp
    order_by: [post_order_by]
    limit: Int
    offset: Int
  ) [Post]
}

# Note: filtering by relations is also supported
input post_bool_exp {
  title: string_bool_exp
  _and: [post_bool_exp]
  _or: [post_bool_exp]
  _not: post_bool_exp
}

input string_bool_exp {
  _neq: String
  _eq: String
  _lte: String
  _lt: String
  _gt: String
  _gte: String
  _in: [String]
  _nin: [String]
  _like: String
  _nlike: String
  _ilike: String
  _nilike: String
  _similar: String
  _nsimilar: String
}

# Note: Sorting by relations is possible as well
input post_order_by {
  title: order_by
}

enum order_by {
  asc
  asc_nulls_last
  asc_nulls_first
  desc
  desc_nulls_first
  desc_nulls_last
}
PostGraphile **Note:** Uses Relay-compliant connections
type Query {
  allPosts(
    filter: PostFilterInput
    orderBy: [PostOrderBy]
    first: Int
    last: ID
    after: ID
    before: ID
  ): PostConnection
}

input PostFilterInput {
  title: StringFilterInput
  and: [PostFilterInput]
  or: [PostFilterInput]
  not: PostFilterInput
}

input StringFilterInput {
  isNull: Boolean
  distinctFrom: String
  notDistinctFrom: String
  equalTo: String
  notEqualTo: String
  lessThan: String
  lessThanOrEqualTo: String
  greaterThan: String
  greaterThanOrEqualTo: String
  in: [String]
  notIn: [String]
}

enum PostOrderBy {
  TITLE_ASC
  TITLE_DESC
}

Create One

AWS Amplify
type Mutation {
  createPost(input: CreatePostInput!): Post
}

input CreatePostInput {
  title: String!
}
Hasura
type Mutation {
  insert_post_one(object: post_insert_input!): Post
}

input post_insert_input {
  title: String!
}
PostGraphile
type Mutation {
  createPost(input: CreatePostInput!): CreatePostPayload
}

type CreatePostPayload {
  post: Post
}

input CreatePostInput {
  post: CreatePostPostInput!
}

input CreatePostPostInput {
  title: String!
}

Create Many

Hasura
type Mutation {
  insert_post(objects: [post_insert_input!]!): post_mutation_response
}

type post_mutation_response {
  affected_rows: Int!
  returning: [Post!]!
}

input post_insert_input {
  title: String!
}

❌ AWS Amplify

❌ PostGraphile

Update One

AWS Amplify **Note:** ID is included in input
type Mutation {
  updatePost(input: UpdatePostInput!): Post
}

input UpdatePostInput {
  id: ID!
  title: String!
}
Hasura
type Mutation {
  update_post_by_pk(
    _inc: post_inc_input
    _set: post_set_input
    pk_columns: post_pk_columns_input!
  ): Post
}

input post_set_input {
  title: String
}

input post_inc_input {
  someIntField: Int
}

input post_pk_columns_input {
  id: ID
}
PostGraphile
type Mutation {
  updatePostById(input: UpdatePostInput!): UpdatePostPayload
}

type UpdatePostPayload {
  post: Post
}

input UpdatePostInput {
  id: ID!
  patch: PostPatchInput!
}

input PostPatchInput {
  title: String
}

Update Many

Hasura
type Mutation {
  update_post_by_pk(
    _inc: post_inc_input
    _set: post_set_input
    # See Find Many for where input type
    where: post_bool_exp
  ): post_mutation_response
}

type post_mutation_response {
  affected_rows: Int!
  returning: [Post!]!
}

input post_set_input {
  title: String
}

input post_inc_input {
  someIntField: Int
}

❌ AWS Amplify

❌ PostGraphile

Delete One

AWS Amplify **Note:** ID is included in input
type Mutation {
  deletePost(input: DeletePostInput!): Post
}

input DeletePostInput {
  id: ID!
}
Hasura
type Mutation {
  delete_post_by_pk(id: ID): Post
}
PostGraphile
type Mutation {
  deletePostById(input: DeletePostInput!): DeletePostPayload
}

type DeletePostPayload {
  deletedPostNodeId: ID
}

input DeletePostInput {
  id: ID!
}

Delete Many

Hasura
type Mutation {
  delete_post(
    # See Find Many for where input type
    where: post_bool_exp
  ): post_mutation_response
}

type post_mutation_response {
  affected_rows: Int!
  returning: [Post!]!
}

❌ AWS Amplify

❌ PostGraphile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment