Skip to content

Instantly share code, notes, and snippets.

@iamclaytonray
Last active March 21, 2019 06:44
Show Gist options
  • Save iamclaytonray/356c572c24e3e1b8b6be79ac8067ec47 to your computer and use it in GitHub Desktop.
Save iamclaytonray/356c572c24e3e1b8b6be79ac8067ec47 to your computer and use it in GitHub Desktop.
GraphQL Pseudo Code

Pseudo Code

type Example {
  first: String
  second: String!
  third: [String]
  fourth: [String!]
  fifth: [String!]!
}
// first
if (type.kind === 'NamedType') {
  // => `String`
}

// second
if (type.kind === 'NonNullType' && type.type.kind === 'NamedType') {
  // => `String!`
}

// third
if (type.kind === 'ListType' && type.type.kind === 'NamedType') {
  // => `[String]`
}

// fourth
if (
  type.kind === 'ListType' &&
  type.type.kind === 'NonNullType' &&
  type.type.type.kind === 'NamedType'
) {
  // => `[String!]`
}

// fifth
if (
  type.kind === 'NonNullType' &&
  type.type.kind === 'ListType' &&
  type.type.type.kind === 'NonNullType' &&
  type.type.type.type.kind === 'NamedType'
) {
  // => `[String!]!`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment