Skip to content

Commit 60ee0b7

Browse files
asiandrummerleebyron
authored andcommitted
fix flow errors from turning on const_params experimental flag (#885)
1 parent da8fe62 commit 60ee0b7

File tree

4 files changed

+91
-31
lines changed

4 files changed

+91
-31
lines changed

.flowconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
[libs]
1010

1111
[options]
12+
experimental.const_params=true

src/execution/execute.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,36 @@ export function execute(
143143
// Extract arguments from object args if provided.
144144
const args = arguments.length === 1 ? argsOrSchema : undefined;
145145
const schema = args ? args.schema : argsOrSchema;
146-
if (args) {
147-
/* eslint-disable no-param-reassign */
148-
document = args.document;
149-
rootValue = args.rootValue;
150-
contextValue = args.contextValue;
151-
variableValues = args.variableValues;
152-
operationName = args.operationName;
153-
fieldResolver = args.fieldResolver;
154-
/* eslint-enable no-param-reassign, no-redeclare */
155-
}
146+
return args ?
147+
executeImpl(
148+
schema,
149+
args.document,
150+
args.rootValue,
151+
args.contextValue,
152+
args.variableValues,
153+
args.operationName,
154+
args.fieldResolver,
155+
) :
156+
executeImpl(
157+
schema,
158+
document,
159+
rootValue,
160+
contextValue,
161+
variableValues,
162+
operationName,
163+
fieldResolver,
164+
);
165+
}
156166

167+
function executeImpl(
168+
schema,
169+
document,
170+
rootValue,
171+
contextValue,
172+
variableValues,
173+
operationName,
174+
fieldResolver
175+
) {
157176
// If arguments are missing or incorrect, throw an error.
158177
assertValidExecutionArguments(
159178
schema,

src/graphql.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,36 @@ export function graphql(
7777
// Extract arguments from object args if provided.
7878
const args = arguments.length === 1 ? argsOrSchema : undefined;
7979
const schema = args ? args.schema : argsOrSchema;
80-
if (args) {
81-
/* eslint-disable no-param-reassign */
82-
source = args.source;
83-
rootValue = args.rootValue;
84-
contextValue = args.contextValue;
85-
variableValues = args.variableValues;
86-
operationName = args.operationName;
87-
fieldResolver = args.fieldResolver;
88-
/* eslint-enable no-param-reassign, no-redeclare */
89-
}
80+
return args ?
81+
graphqlImpl(
82+
schema,
83+
args.source,
84+
args.rootValue,
85+
args.contextValue,
86+
args.variableValues,
87+
args.operationName,
88+
args.fieldResolver,
89+
) :
90+
graphqlImpl(
91+
schema,
92+
source,
93+
rootValue,
94+
contextValue,
95+
variableValues,
96+
operationName,
97+
fieldResolver,
98+
);
99+
}
90100

101+
function graphqlImpl(
102+
schema,
103+
source,
104+
rootValue,
105+
contextValue,
106+
variableValues,
107+
operationName,
108+
fieldResolver
109+
) {
91110
return new Promise(resolve => {
92111
// Parse
93112
let document;

src/subscription/subscribe.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,39 @@ export function subscribe(
7373
// Extract arguments from object args if provided.
7474
const args = arguments.length === 1 ? argsOrSchema : undefined;
7575
const schema = args ? args.schema : argsOrSchema;
76-
if (args) {
77-
/* eslint-disable no-param-reassign */
78-
document = args.document;
79-
rootValue = args.rootValue;
80-
contextValue = args.contextValue;
81-
variableValues = args.variableValues;
82-
operationName = args.operationName;
83-
fieldResolver = args.fieldResolver;
84-
subscribeFieldResolver = args.subscribeFieldResolver;
85-
/* eslint-enable no-param-reassign, no-redeclare */
86-
}
76+
return args ?
77+
subscribeImpl(
78+
schema,
79+
args.document,
80+
args.rootValue,
81+
args.contextValue,
82+
args.variableValues,
83+
args.operationName,
84+
args.fieldResolver,
85+
args.subscribeFieldResolver,
86+
) :
87+
subscribeImpl(
88+
schema,
89+
document,
90+
rootValue,
91+
contextValue,
92+
variableValues,
93+
operationName,
94+
fieldResolver,
95+
subscribeFieldResolver,
96+
);
97+
}
8798

99+
function subscribeImpl(
100+
schema,
101+
document,
102+
rootValue,
103+
contextValue,
104+
variableValues,
105+
operationName,
106+
fieldResolver,
107+
subscribeFieldResolver
108+
) {
88109
const subscription = createSourceEventStream(
89110
schema,
90111
document,

0 commit comments

Comments
 (0)