How to use the graphql.buildSchema function in graphql

To help you get started, we’ve selected a few graphql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kamilkisiela / graphql-inspector / packages / core / __tests__ / diff / enum.ts View on Github external
test('description changed', () => {
    const a = buildSchema(/* GraphQL */ `
      type Query {
        fieldA: String
      }

      """
      Old Description
      """
      enum enumA {
        A
        B
      }
    `);

    const b = buildSchema(/* GraphQL */ `
      type Query {
        fieldA: String
      }

      """
      New Description
      """
      enum enumA {
        A
        B
      }
    `);

    const changes = diff(a, b);
    const change = findFirstChangeByPath(changes, 'enumA');
github kamilkisiela / graphql-inspector / packages / core / __tests__ / diff / interface.ts View on Github external
test('added', async () => {
      const a = buildSchema(/* GraphQL */ `
        interface Foo {
          a: String!
          b: String!
        }
      `);
      const b = buildSchema(/* GraphQL */ `
        interface Foo {
          a: String!
          b: String!
          c: String!
        }
      `);

      const change = findFirstChangeByPath(await diff(a, b), 'Foo.c');

      expect(change.criticality.level).toEqual(CriticalityLevel.NonBreaking);
github dangcuuson / graphql-schema-typescript / src / index.ts View on Github external
if (isString(schema)) {
        // is is a path to schema folder?
        try {
            const schemaPath = path.resolve(schema);
            const exists = fs.existsSync(schemaPath);
            if (exists) {
                introspectResult = await introspectSchemaViaLocalFile(schemaPath);
            }
        } catch {
            // fall-through in case the provided string is a graphql definition,
            // which can make path.resolve throw error
        }

        // it's not a folder, maybe it's a schema definition
        if (!introspectResult) {
            const schemaViaStr = buildSchema(schema);
            introspectResult = await introspectSchema(schemaViaStr);
        }
    } else {
        introspectResult = await introspectSchema(schema);
    }

    const tsGenerator = new TypeScriptGenerator(mergedOptions, introspectResult);
    const typeDefs = await tsGenerator.generate();

    let typeResolvers: GenerateResolversResult = {
        body: [],
        importHeader: []
    };
    const tsResolverGenerator = new TSResolverGenerator(mergedOptions, introspectResult);
    typeResolvers = await tsResolverGenerator.generate();
github symm / graphql-contract-test / src / index.ts View on Github external
function getContractSchema(expectedSchemaFile: string): GraphQLSchema {
    const data = fs.readFileSync(expectedSchemaFile, "utf8")

    return buildSchema(data)
}
github cerebral / cerebral / demos / todomvc / src / GraphQl / index.js View on Github external
function Module (options = {}) {
  const schema = buildSchema(options.schema);

  return ({controller, path}) => {
    return {
      state: {},
      signals: {
        test: [
          function query ({graphql, props}) {
            return graphql.query(props.query)
          },
          function setResponse ({props, state}) {
            state.set(`graphql.data`, props.data)
          }
        ]
      },
      provider (context) {
        const resolvers = Object.assign({}, options.root);
github fabsrc / graphql-schema-diff / src / diff.ts View on Github external
function readLocalSchema(schemaPath: string): GraphQLSchema {
  let schemaString: string;

  if (isGlob(schemaPath)) {
    const typesArray = fileLoader(schemaPath);

    if (typesArray.length === 0) {
      throw new Error(`No types found with glob pattern '${schemaPath}'`);
    }

    schemaString = mergeTypes(typesArray, { all: true });
  } else {
    schemaString = fs.readFileSync(schemaPath, 'utf8');
  }

  const schema = buildSchema(schemaString);
  const introspection = introspectionFromSchema(schema, {
    descriptions: false
  });
  return buildClientSchema(introspection);
}
github barretodavid / rest-to-graphql / src / server.ts View on Github external
import { buildSchema } from 'graphql';
import * as Koa from 'koa';
import * as mount from 'koa-mount';
import * as convert from 'koa-convert';
import * as graphqlHTTP from 'koa-graphql';

import './connect';
import { User, Post, Album } from './models';
import { UserModel, PostModel, AlbumModel } from './interfaces';

const HTTP_PORT = 3000;
const app = new Koa();

const mySchema = buildSchema(`
  type Geo {
    lat: String
    lng: String
  }

  type Address {
    street: String
    suite: String
    city: String
    zipcode: String
    geo: Geo
  }
  
  type Company {
    name: String
    catchPhrase: String
github zeit / vrs / backend / api / graphql / index.js View on Github external
const express = require("express");
const expressGraphQL = require("express-graphql");
const { buildSchema } = require("graphql");

const schema = buildSchema(`
  type Query {
    hello: String
  }
`);

const rootValue = {
  hello: () => {
    return "hello vrs";
  }
};

const app = express();

app.use(
  "*",
  expressGraphQL({
github kamilkisiela / graphql-inspector / packages / github / src / probot.ts View on Github external
await check.complete({
      url,
      context,
      conclusion: CheckConclusion.Failure,
    });
    return;
  }

  const oldPointer: SchemaPointer = config.schema;
  const newPointer: SchemaPointer = {
    path: oldPointer.path,
    ref,
  };

  const schemas = {
    old: buildSchema(await loadFile(oldPointer)),
    new: buildSchema(await loadFile(newPointer)),
  };

  context.log.info(`Both schemas built - ${id}`);

  const actions: Array> = [];

  if (config.diff) {
    actions.push(
      diff({
        path: config.schema.path,
        schemas,
      }),
    );
  }