Merge pull request #1995 from Apollinaire/runqueryRename

runQuery->runGraphQL
This commit is contained in:
Sacha Greif 2018-06-13 08:38:33 +09:00 committed by GitHub
commit 05a0e78904
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,6 @@
/*
Run a GraphQL query from the server with the proper context
Run a GraphQL request from the server with the proper context
*/
import { graphql } from 'graphql';
@ -12,13 +12,13 @@ import { getDefaultFragmentText, extractFragmentName, getFragmentText } from '..
import { getSetting } from '../modules/settings';
import merge from 'lodash/merge';
// note: if no context is passed, default to running queries with full admin privileges
export const runQuery = async (query, variables = {}, context ) => {
// note: if no context is passed, default to running requests with full admin privileges
export const runGraphQL = async (query, variables = {}, context ) => {
const defaultContext = { currentUser: {isAdmin: true}, locale: getSetting('locale') };
const queryContext = merge(defaultContext, context);
// within the scope of this specific query,
// within the scope of this specific request,
// decorate each collection with a new Dataloader object and add it to context
Collections.forEach(collection => {
collection.loader = new DataLoader(ids => findByIds(collection, ids, queryContext), { cache: true });
@ -30,7 +30,7 @@ export const runQuery = async (query, variables = {}, context ) => {
if (result.errors) {
// eslint-disable-next-line no-console
console.error(`runQuery error: ${result.errors[0].message}`);
console.error(`runGraphQL error: ${result.errors[0].message}`);
// eslint-disable-next-line no-console
console.error(result.errors);
throw new Error(result.errors[0].message);
@ -39,6 +39,8 @@ export const runQuery = async (query, variables = {}, context ) => {
return result;
}
export const runQuery = runGraphQL; //backwards compatibility
/*
Given a collection and a fragment, build a query to fetch one document.
@ -92,4 +94,4 @@ Meteor.startup(() => {
});
});
});