dotansimha / graphql-typed-ast

Experimental TypeScript type-based parser for GraphQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

graphql-typed-ast

Experimental TypeScript type-based parser for GraphQL.

This repo is for experimental TypeScript type-system based parser for GraphQL, for creating a real time resolvers-signature based on GraphQL SDL.

It uses a custom alpha version of TypeScript from this PR.

Goals

  • GraphQL Lexer
  • GraphQL Document Parser

Example

The goal of this experiment is to allow this:

const ast = `
       type Query { user(id: ID!): User! }
       type User { id: ID!, name: String! }
    `;

const resolvers: ResolverFor<
   typeof ast,
    { User: UserModel },
    ContextType
  > = {
  Query: {
    user(parent, { id }, context) => {
       // parent is null, id is string | number, context is ContextType, expected return type is `UserModel` 
    } 
  },
  User: {
    name: (parent, args, context) => {
      // parent is UserModel, args is {}, context is ContextType, expected return type is `string`
    }
  }
};

About

Experimental TypeScript type-based parser for GraphQL

License:MIT License


Languages

Language:TypeScript 100.0%