How to use the graphql.graphql 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 excitement-engineer / graphql-iso-date / examples / localDate / input.js View on Github external
// The date parameter is a Javascript Date object
          return date
        }
      }
    }
  })
})

graphql(schema, `{ input(date: "2016-02-01") }`)
    .then(result => {
      console.log(`Example query { input(date: "2016-02-01") }: Input a valid date and output the same date`)
      console.log(result)
    })
    .catch(console.error)

graphql(schema, `{ input(date: "2015-02-29") }`)
    .then(result => {
      console.log(`Example query { input(date: "2015-02-29") }: Output an error when an invalid date is passed as input (29 Feb 2015 doesn't exist)`)
      console.log(result)
    })
    .catch(console.error)
github artsy / metaphysics / test / schema / home / home_page_artist_module.js View on Github external
it("does not return any suggestions", () => {
      return graphql(schema, query("SUGGESTED")).then(response => {
        expect(response.data.home_page.artist_module.results).toBe(null)
        expect(response.errors.length).toBeGreaterThan(0)
      })
    })
  })
github MichalLytek / type-graphql / tests / functional / resolvers.ts View on Github external
it("should create instance of input object", async () => {
      const mutation = `mutation {
        mutationWithInput(input: { factor: 10 })
      }`;

      const mutationResult = await graphql(schema, mutation);
      const result = mutationResult.data!.mutationWithInput;

      expect(result).toBeGreaterThanOrEqual(0);
      expect(result).toBeLessThanOrEqual(10);
    });
github lucasconstantino / graphql-resolvers / test / dependingResolvers.js View on Github external
it('should resolve value normally, even when resolved to a promise', async () => {
        const { schema, sources: { delayedDependee } } = setup()
        const result = await graphql(schema, '{ type { delayedDependee } }', null, {})
        expect(result).to.have.deep.property('data.type.delayedDependee', 'delayedDependee value')
        expect(delayedDependee).to.have.been.called.once
      })
github ConsenSys / ethql / src / __tests__ / utils.ts View on Github external
const execQuery = (query: string, context?: EthqlContext, variables?: { [key: string]: any }) => {
    return graphql(schema, query, {}, context || prepareContext(), variables);
  };
github DxCx / webpack-graphql-server / src / schema.spec.ts View on Github external
it("should find a person correctly", () => {
    let testQuery = `{
             getPerson(id: "3"){
                name
                id
            }
        }`;

    return graphql(Schema, testQuery, undefined, {persons, findPerson, addPerson}).then((res) => {
      assertNoError(res);
      expect(res.data).toMatchSnapshot();
    });
  });
github 3VLINC / graphql-to-typescript / src / compile-graphql.ts View on Github external
}

        if (typeDefs.length === 0) {

          throw new Error(`No type definitions were found matching: ${options.graphqlFileGlob}`);

        }

        output.push(`export const typeDefs = ${JSON.stringify(typeDefs)};`);

        const schema = makeExecutableSchema({ typeDefs });

        const [introspectionResult, template] = await Promise.all(
          [
            graphql(schema, introspectionQuery),
            getTemplateGenerator('typescript'),
          ]
        );

        const introspection = introspectionResult.data;

        const transformOptions = {
          introspection,
          documents: [],
          template: template,
          outPath: './',
          isDev: false,
          noSchema: false,
          noDocuments: true,
        } as TransformedOptions;
github vulcainjs / vulcain-corejs / src / graphql / graphQLHandler.ts View on Github external
async graphql(g: any) {
        let response = await graphql.graphql(this.graphQuerySchema, g.query || g, null, this.context, g.variables);
        if (this.metadata.metadata.responseType === "graphql")
            return new HttpResponse(response);

        if (response.errors && response.errors.length > 0) {
            throw new ApplicationError(response.errors[0].message);
        }
        return response.data;
    }
}
github reindexio / reindex-api / graphQL / Reindex.js View on Github external
async processRequest(request) {
    const query = request.payload.query;
    const variables = request.payload.variables || {};
    const credentials = request.auth.credentials;
    const db = await request.getDB();

    const {
      schema,
      context,
    } = await this.getOptions({ db, credentials });

    const start = process.hrtime();
    const result = await graphql(
      schema,
      query,
      null,
      context,
      variables
    );
    const elapsed = process.hrtime(start);

    let rootName = 'unknown';
    let hasErrors = false;

    if (result.data) {
      rootName = Object.keys(result.data).sort().join(',');
      if (rootName === 'viewer') {
        rootName = Object.keys(result.data.viewer).sort().join(',');
      }
github segphault / basejump-router / src / requests.js View on Github external
processGraphQL(name, context) {
    let {schema, resolvers} = this.graphql.getSchema(name);
    let {query, variables} = context.params.body;
    let actions = {};

    for (let {id, action} of resolvers)
      actions[id] = params =>
        this.sandbox(action, Object.assign({}, context, {params}));

    return graphql(schema, query, actions, variables);
  }