Skip to content

Instantly share code, notes, and snippets.

@tmeasday
Created August 3, 2017 01:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmeasday/51d0c9fe2d1b7acc5e1aece59b1ff658 to your computer and use it in GitHub Desktop.
Save tmeasday/51d0c9fe2d1b7acc5e1aece59b1ff658 to your computer and use it in GitHub Desktop.
import { execute } from 'graphql';
import { makeExecutableSchema } from 'graphql-tools';
// There is some code duplication with server/index here.
// I wonder if we could refactor?
import addModelsToContext from '../model';
import typeDefs from '../schema';
import resolvers from '../resolvers';
/* eslint-disable no-console */
const temp = console.warn;
console.warn = null;
const schema = makeExecutableSchema({ typeDefs, resolvers });
console.warn = temp;
/* eslint-enable no-console */
// Mock
const pubsub = {
publish() {},
};
// run a query against our resolvers/models with the given db
export default async function runQuery(db, query, varables = {}) {
const context = addModelsToContext({ db, pubsub });
const { data, error } = await execute(schema, query, {}, context, varables);
if (error) {
throw error;
}
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment