Skip to content

Commit 3142d87

Browse files
committed
Add tests to ensure resolve info contains correct information.
Fixes #473
1 parent 6a0e00f commit 3142d87

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

src/execution/__tests__/executor-test.js

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

186+
it('provides info about current execution state', async () => {
187+
const ast = parse('query ($var: String) { result: test }');
188+
189+
let info;
190+
191+
const schema = new GraphQLSchema({
192+
query: new GraphQLObjectType({
193+
name: 'Test',
194+
fields: {
195+
test: {
196+
type: GraphQLString,
197+
resolve(val, args, ctx, _info) {
198+
info = _info;
199+
}
200+
}
201+
}
202+
})
203+
});
204+
205+
const rootValue = { root: 'val' };
206+
207+
await execute(schema, ast, rootValue, null, { var: 123 });
208+
209+
expect(Object.keys(info)).to.deep.equal([
210+
'fieldName',
211+
'fieldASTs',
212+
'returnType',
213+
'parentType',
214+
'path',
215+
'schema',
216+
'fragments',
217+
'rootValue',
218+
'operation',
219+
'variableValues',
220+
]);
221+
expect(info.fieldName).to.equal('test');
222+
expect(info.fieldASTs).to.have.lengthOf(1);
223+
expect(info.fieldASTs[0]).to.equal(
224+
ast.definitions[0].selectionSet.selections[0]
225+
);
226+
expect(info.returnType).to.equal(GraphQLString);
227+
expect(info.parentType).to.equal(schema.getQueryType());
228+
expect(info.path).to.deep.equal([ 'result' ]);
229+
expect(info.schema).to.equal(schema);
230+
expect(info.rootValue).to.equal(rootValue);
231+
expect(info.operation).to.equal(ast.definitions[0]);
232+
expect(info.variableValues).to.deep.equal({ var: '123' });
233+
});
234+
186235
it('threads root value context correctly', async () => {
187236
const doc = 'query Example { a }';
188237

src/execution/execute.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type ExecutionContext = {
9090
operation: OperationDefinition;
9191
variableValues: {[key: string]: mixed};
9292
errors: Array<GraphQLError>;
93-
}
93+
};
9494

9595
/**
9696
* The result of execution. `data` is the result of executing the
@@ -100,7 +100,7 @@ type ExecutionContext = {
100100
type ExecutionResult = {
101101
data: ?Object;
102102
errors?: Array<GraphQLError>;
103-
}
103+
};
104104

105105
/**
106106
* Implements the "Evaluating requests" section of the GraphQL specification.

0 commit comments

Comments
 (0)