Created
August 3, 2017 01:21
-
-
Save tmeasday/51d0c9fe2d1b7acc5e1aece59b1ff658 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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