Skip to content

Commit 09a44e4

Browse files
author
clintwood (Office)
committed
Merge remote-tracking branch 'upstream/master' into annotations
2 parents 1933963 + c7e6a75 commit 09a44e4

File tree

4 files changed

+41
-51
lines changed

4 files changed

+41
-51
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql",
3-
"version": "0.4.18",
3+
"version": "0.5.0-beta.1",
44
"description": "A Query Language and Runtime which can target any service.",
55
"contributors": [
66
"Lee Byron <[email protected]> (http://leebyron.com/)",

src/execution/__tests__/directives-test.js

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -268,47 +268,28 @@ describe('Execute: handles directives', () => {
268268
});
269269
});
270270

271-
describe('works on fragment', () => {
272-
it('if false omits fragment', async () => {
273-
const q = `
274-
query Q {
275-
a
276-
...Frag
277-
}
278-
fragment Frag on TestType @include(if: false) {
279-
b
280-
}
281-
`;
282-
return expect(await executeTestQuery(q)).to.deep.equal({
283-
data: { a: 'a' }
271+
describe('works with skip and include directives', () => {
272+
it('include and no skip', async () => {
273+
return expect(
274+
await executeTestQuery('{ a, b @include(if: true) @skip(if: false) }')
275+
).to.deep.equal({
276+
data: { a: 'a', b: 'b' }
284277
});
285278
});
286-
it('if true includes fragment', async () => {
287-
const q = `
288-
query Q {
289-
a
290-
...Frag
291-
}
292-
fragment Frag on TestType @include(if: true) {
293-
b
294-
}
295-
`;
296-
return expect(await executeTestQuery(q)).to.deep.equal({
297-
data: { a: 'a', b: 'b' }
279+
280+
it('include and skip', async () => {
281+
return expect(
282+
await executeTestQuery('{ a, b @include(if: true) @skip(if: true) }')
283+
).to.deep.equal({
284+
data: { a: 'a' }
298285
});
299286
});
300-
it('unless false includes fragment', async () => {
301-
const q = `
302-
query Q {
303-
a
304-
...Frag
305-
}
306-
fragment Frag on TestType @skip(if: false) {
307-
b
308-
}
309-
`;
310-
return expect(await executeTestQuery(q)).to.deep.equal({
311-
data: { a: 'a', b: 'b' }
287+
288+
it('no include or skip', async () => {
289+
return expect(
290+
await executeTestQuery('{ a, b @include(if: false) @skip(if: false) }')
291+
).to.deep.equal({
292+
data: { a: 'a' }
312293
});
313294
});
314295
});

src/execution/__tests__/executor-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,23 @@ describe('Execute: Handles basic execution tasks', () => {
183183
});
184184
});
185185

186-
it('threads context correctly', async () => {
186+
it('threads root value context correctly', async () => {
187187
const doc = 'query Example { a }';
188188

189189
const data = {
190190
contextThing: 'thing',
191191
};
192192

193-
let resolvedContext;
193+
let resolvedRootValue;
194194

195195
const schema = new GraphQLSchema({
196196
query: new GraphQLObjectType({
197197
name: 'Type',
198198
fields: {
199199
a: {
200200
type: GraphQLString,
201-
resolve(context) {
202-
resolvedContext = context;
201+
resolve(rootValue) {
202+
resolvedRootValue = rootValue;
203203
}
204204
}
205205
}
@@ -208,7 +208,7 @@ describe('Execute: Handles basic execution tasks', () => {
208208

209209
await execute(schema, parse(doc), data);
210210

211-
expect(resolvedContext.contextThing).to.equal('thing');
211+
expect(resolvedRootValue.contextThing).to.equal('thing');
212212
});
213213

214214
it('correctly threads arguments', async () => {

src/execution/execute.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ function collectFields(
409409
visitedFragmentNames[fragName] = true;
410410
const fragment = exeContext.fragments[fragName];
411411
if (!fragment ||
412-
!shouldIncludeNode(exeContext, fragment.directives) ||
413412
!doesFragmentConditionMatch(exeContext, fragment, runtimeType)) {
414413
continue;
415414
}
@@ -444,7 +443,9 @@ function shouldIncludeNode(
444443
skipAST.arguments,
445444
exeContext.variableValues
446445
);
447-
return !skipIf;
446+
if (skipIf === true) {
447+
return false;
448+
}
448449
}
449450

450451
const includeAST = directives && find(
@@ -457,7 +458,9 @@ function shouldIncludeNode(
457458
includeAST.arguments,
458459
exeContext.variableValues
459460
);
460-
return Boolean(includeIf);
461+
if (includeIf === false) {
462+
return false;
463+
}
461464
}
462465

463466
return true;
@@ -817,12 +820,18 @@ function completeAbstractValue(
817820
returnType.resolveType(result, exeContext.contextValue, info) :
818821
defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);
819822

820-
if (!runtimeType) {
821-
return null;
822-
}
823+
invariant(
824+
runtimeType,
825+
`Could not determine runtime type of value "${result}" for field ${
826+
info.parentType}.${info.fieldName}.`
827+
);
828+
invariant(
829+
runtimeType instanceof GraphQLObjectType,
830+
`${returnType}.resolveType must return an instance of GraphQLObjectType ` +
831+
`for field ${info.parentType}.${info.fieldName}, received "${runtimeType}".`
832+
);
823833

824-
const schema = exeContext.schema;
825-
if (runtimeType && !schema.isPossibleType(returnType, runtimeType)) {
834+
if (!exeContext.schema.isPossibleType(returnType, runtimeType)) {
826835
throw new GraphQLError(
827836
`Runtime Object type "${runtimeType}" is not a possible type ` +
828837
`for "${returnType}".`,

0 commit comments

Comments
 (0)