GraphQL

Write an awesome doc for GraphQL. A very nice an practical one extracted from GraphQL official documentation.

View on GitHub

Functions provided by graphql

I missed this part and actually I had to come back to this part and learn about it. In fact I was trying to work with GraphQL query in my server and remove some stuff from it just so that I can do something else. And I was literally doing string manipulation and then it dawned on me that I am not the first person who needs these things so let’s see how others are doing it.

Besides my approach felt like reinventing the wheel and TBF it also was not as safe as how folks at GraphQL-JS probably had done it.

parse

import { parse } from 'graphql';
const query = /* GraphQL */ `
  query {
    getUsers(first: 10) {
      id
    }
  }
`;
const ast = parse(query);

Find the complete implementation here

buildASTSchema

import { parse, buildASTSchema } from 'graphql';
const schemaString = /* GraphQL */ `
  type User {
    id: ID!
  }
  type Query {
    getUsers(first: Int!): [User!]
  }
`;
const ast = parse(schemaString);
const schema = buildASTSchema(ast);

validate

execute

print

import { DocumentNode, parse, print } from 'graphql';
const query = /* GraphQL */ `
  query {
    getUsers(first: 10) {
      id
    }
  }
`;
const ast = parse(query);
const definitionNode = (ast as DocumentNode).definitions[0];
print(definitionNode);

printSchema

Returns the schema of a GraphQLSchema instance in the form of a string.

graphql

[!TIP]

Orchestrates the invocations of the resolver functions and package the response data according to the shape of the provided query.