Skip to content

Commit

Permalink
fix flow errors from turning on const_params experimental flag (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
asiandrummer authored and leebyron committed May 26, 2017
1 parent da8fe62 commit 60ee0b7
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 31 deletions.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
[libs]

[options]
experimental.const_params=true
39 changes: 29 additions & 10 deletions src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,36 @@ export function execute(
// Extract arguments from object args if provided.
const args = arguments.length === 1 ? argsOrSchema : undefined;
const schema = args ? args.schema : argsOrSchema;
if (args) {
/* eslint-disable no-param-reassign */
document = args.document;
rootValue = args.rootValue;
contextValue = args.contextValue;
variableValues = args.variableValues;
operationName = args.operationName;
fieldResolver = args.fieldResolver;
/* eslint-enable no-param-reassign, no-redeclare */
}
return args ?
executeImpl(
schema,
args.document,
args.rootValue,
args.contextValue,
args.variableValues,
args.operationName,
args.fieldResolver,
) :
executeImpl(
schema,
document,
rootValue,
contextValue,
variableValues,
operationName,
fieldResolver,
);
}

function executeImpl(
schema,
document,
rootValue,
contextValue,
variableValues,
operationName,
fieldResolver
) {
// If arguments are missing or incorrect, throw an error.
assertValidExecutionArguments(
schema,
Expand Down
39 changes: 29 additions & 10 deletions src/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,36 @@ export function graphql(
// Extract arguments from object args if provided.
const args = arguments.length === 1 ? argsOrSchema : undefined;
const schema = args ? args.schema : argsOrSchema;
if (args) {
/* eslint-disable no-param-reassign */
source = args.source;
rootValue = args.rootValue;
contextValue = args.contextValue;
variableValues = args.variableValues;
operationName = args.operationName;
fieldResolver = args.fieldResolver;
/* eslint-enable no-param-reassign, no-redeclare */
}
return args ?
graphqlImpl(
schema,
args.source,
args.rootValue,
args.contextValue,
args.variableValues,
args.operationName,
args.fieldResolver,
) :
graphqlImpl(
schema,
source,
rootValue,
contextValue,
variableValues,
operationName,
fieldResolver,
);
}

function graphqlImpl(
schema,
source,
rootValue,
contextValue,
variableValues,
operationName,
fieldResolver
) {
return new Promise(resolve => {
// Parse
let document;
Expand Down
43 changes: 32 additions & 11 deletions src/subscription/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,39 @@ export function subscribe(
// Extract arguments from object args if provided.
const args = arguments.length === 1 ? argsOrSchema : undefined;
const schema = args ? args.schema : argsOrSchema;
if (args) {
/* eslint-disable no-param-reassign */
document = args.document;
rootValue = args.rootValue;
contextValue = args.contextValue;
variableValues = args.variableValues;
operationName = args.operationName;
fieldResolver = args.fieldResolver;
subscribeFieldResolver = args.subscribeFieldResolver;
/* eslint-enable no-param-reassign, no-redeclare */
}
return args ?
subscribeImpl(
schema,
args.document,
args.rootValue,
args.contextValue,
args.variableValues,
args.operationName,
args.fieldResolver,
args.subscribeFieldResolver,
) :
subscribeImpl(
schema,
document,
rootValue,
contextValue,
variableValues,
operationName,
fieldResolver,
subscribeFieldResolver,
);
}

function subscribeImpl(
schema,
document,
rootValue,
contextValue,
variableValues,
operationName,
fieldResolver,
subscribeFieldResolver
) {
const subscription = createSourceEventStream(
schema,
document,
Expand Down

0 comments on commit 60ee0b7

Please sign in to comment.