Skip to content
/ gqb Public

GraphQL schema language with resolvers inlining

Notifications You must be signed in to change notification settings

istarkov/gqb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GQB

This package allows you to injects type resolvers directly into GraphQL schema language.

Why

A lot of boilerplate code if write schemas on javascript graphql-js.

This is better graphql-tools but resolvers described after the schema.

How it works

import { gqb, getResolvers } from 'gqb';
import { graphql } from 'graphql';
import { makeExecutableSchema } from 'graphql-tools';

const schema = gqb`
  type Query {
    hello: String${ // field resolver source
      () => 'World'
    },
    pic(size: Int): String${
      (_, { size }) => `pic size is: ${size}`
    }
  }

  type Mutation {
    setMessage(message: String): String${ // mutation source
      (_, { message }) => `Mutated ${message}`
    }
  }
`;

const executableSchema = makeExecutableSchema(
  getResolvers(schema)
);

graphql(
  executableSchema,
  '{ hello, pic(size: 20)}'
)
.then(response => console.log(response));

Type fields resolver now are placed directly in the schema, immediatelly after type!!!

It also supports schema inlining, (see tests)

See the source it's small.

Install

npm install --save gqb

TODO

Type resolvers

PS

Haven't tested at all except current repo tests, just an idea.

About

GraphQL schema language with resolvers inlining

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published