Coder Social home page Coder Social logo
GraphQL Factory photo

graphql-factory Goto Github PK

repos: 7.0 gists: 0.0

Name: GraphQL Factory

Type: Organization

Bio: A GraphQL toolkit for programmatically building schemas

Location: Orange County, CA

graphql-factory

Tools for building GraphQL

Announcements

  • Alpha releases have started...

  • Documentation on graphqlfactory.io is not currently up to date. This announcement will be removed when it is.

This project is currently undergoing a major re-write for v3.0.0. This will include

  • a more graphql-like api
  • updated GraphQL Factory Definition Format
  • custom execution which will allow
    • custom directive middleware support
    • tracing data for all resolves/middleware
  • Schema building tools
  • Schema language support
  • better code testing
  • and more...

v2.1.0 code is available in the v2.1.0 branch. The master branch will be used for v3.0.0 development

Schema Language Example

Create a schema from schema language and a SchemaBacking

import { graphql } from 'graphql'
import {
  SchemaDefinition,
  SchemaBacking
} from 'graphql-factory'

// create a schema language definition
const definition = `
  type Item {
    id: String!
    name: String!
  }

  type List {
    id: String!
    name: String!
    items: [Item]!
  }

  type Query {
    listLists (search: String): [List]
  }

  directive @test(value: String) on SCHEMA | OBJECT | QUERY | FIELD

  schema @test(value: "I am a schema directive") {
    query: Query
  }`

// create a schema backing that contains resolvers
const backing = new SchemaBacking()
  .Directive('test')
    .before((source, args, context, info) => {
      console.log('Testing', args)
    })
  .Object('Query')
    .resolve('listLists', (source, args, context, info) => {
      // resolve code
    })
  .Object('List')
    .resolve('items', (source, args, context, info) => {
      // resolve code
    })
  .backing();

const schema = new SchemaDefinition()
    .use(definition, backing)
    .buildSchema();

schema.request({
  source: `
    query MyQuery {
      listLists {
        name
        items {
          name
        }
      }
    }
  `
})
.then(result => {
  // code...
});

Factory Definition Example

Create the same schema using GraphQL Factory Definition Format

import { graphql } from 'graphql'
import { SchemaDefinition } from 'graphql-factory'

// graphql factory definition which includes
// definitions and resolvers
const definition = {
  directives: {
    test: {
      locations: [ 'SCHEMA', 'OBJECT', 'QUERY', 'FIELD' ],
      args: {
        value: { type: 'String' }
      },
      before(source, args, context, info) {
        console.log('Testing', args)
      }
    }
  },
  types: {
    Item: {
      type: 'Object',
      fields: {
        id: { type: 'String!' },
        name: { type: 'String!' }
      }
    },
    List: {
      type: 'Object',
      fields: {
        id: { type: 'String!' },
        name: { type: 'String!' },
        items: {
          type: '[Item]!',
          resolve(source, args, context, info) {
            // resolve code
          }
        }
      }
    },
    Query: {
      type: 'Object',
      fields: {
        listLists: {
          type: '[List]',
          args: {
            search: { type: 'String' }
          },
          resolve(source, args, context, info) {
            // resolve code
          }
        }
      }
    }
  },
  schema: {
    directives: [ 'test' ],
    query: 'Query',
    '@directives': {
      test: {
        value: 'I am a schema directive'
      }
    }
  }
}

const schema = new SchemaDefinition()
    .use(definition, backing)
    .buildSchema();

schema.request({
  source: `
    query MyQuery {
      listLists {
        name
        items {
          name
        }
      }
    }
  `
})
.then(result => {
  // code...
});

GraphQL Factory's Projects

graphql icon graphql

An implementation of GraphQL for Go / Golang

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.