Skip to content

[RFC] Add explicit context arg to graphql execution #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/__tests__/starWarsQueryTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe('Star Wars Query Tests', () => {
name: 'Luke Skywalker'
}
};
const result = await graphql(StarWarsSchema, query, null, params);
const result = await graphql(StarWarsSchema, query, null, null, params);
expect(result).to.deep.equal({ data: expected });
});

Expand All @@ -201,7 +201,7 @@ describe('Star Wars Query Tests', () => {
name: 'Han Solo'
}
};
const result = await graphql(StarWarsSchema, query, null, params);
const result = await graphql(StarWarsSchema, query, null, null, params);
expect(result).to.deep.equal({ data: expected });
});

Expand All @@ -219,7 +219,7 @@ describe('Star Wars Query Tests', () => {
const expected = {
human: null
};
const result = await graphql(StarWarsSchema, query, null, params);
const result = await graphql(StarWarsSchema, query, null, null, params);
expect(result).to.deep.equal({ data: expected });
});
});
Expand Down
16 changes: 9 additions & 7 deletions src/execution/__tests__/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('Execute: Handles basic execution tasks', () => {
});

expect(
await execute(schema, ast, data, { size: 100 }, 'Example')
await execute(schema, ast, data, null, { size: 100 }, 'Example')
).to.deep.equal(expected);
});

Expand Down Expand Up @@ -427,7 +427,7 @@ describe('Execute: Handles basic execution tasks', () => {
})
});

const result = await execute(schema, ast, data, null, 'OtherExample');
const result = await execute(schema, ast, data, null, null, 'OtherExample');

expect(result).to.deep.equal({ data: { second: 'b' } });
});
Expand Down Expand Up @@ -481,7 +481,9 @@ describe('Execute: Handles basic execution tasks', () => {
})
});

expect(() => execute(schema, ast, data, null, 'UnknownExample')).to.throw(
expect(() =>
execute(schema, ast, data, null, null, 'UnknownExample')
).to.throw(
'Unknown operation named "UnknownExample".'
);
});
Expand Down Expand Up @@ -511,7 +513,7 @@ describe('Execute: Handles basic execution tasks', () => {
})
});

const queryResult = await execute(schema, ast, data, {}, 'Q');
const queryResult = await execute(schema, ast, data, null, {}, 'Q');

expect(queryResult).to.deep.equal({ data: { a: 'b' } });
});
Expand All @@ -535,7 +537,7 @@ describe('Execute: Handles basic execution tasks', () => {
})
});

const mutationResult = await execute(schema, ast, data, {}, 'M');
const mutationResult = await execute(schema, ast, data, null, {}, 'M');

expect(mutationResult).to.deep.equal({ data: { c: 'd' } });
});
Expand All @@ -559,7 +561,7 @@ describe('Execute: Handles basic execution tasks', () => {
})
});

const subscriptionResult = await execute(schema, ast, data, {}, 'S');
const subscriptionResult = await execute(schema, ast, data, null, {}, 'S');

expect(subscriptionResult).to.deep.equal({ data: { a: 'b' } });
});
Expand Down Expand Up @@ -644,7 +646,7 @@ describe('Execute: Handles basic execution tasks', () => {
}),
});

const queryResult = await execute(schema, ast, data, {}, 'Q');
const queryResult = await execute(schema, ast, data, null, {}, 'Q');

expect(queryResult).to.deep.equal({ data: { a: 'b' } });
});
Expand Down
13 changes: 9 additions & 4 deletions src/execution/__tests__/union-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ describe('Execute: Union and intersection types', () => {
});

it('gets execution info in resolver', async () => {
let encounteredContext;
let encounteredSchema;
let encounteredRootValue;

Expand All @@ -357,9 +358,10 @@ describe('Execute: Union and intersection types', () => {
fields: {
name: { type: GraphQLString }
},
resolveType(obj, { schema: infoSchema, rootValue: infoRootValue }) {
encounteredSchema = infoSchema;
encounteredRootValue = infoRootValue;
resolveType(obj, context, { schema: _schema, rootValue }) {
encounteredContext = context;
encounteredSchema = _schema;
encounteredRootValue = rootValue;
return PersonType2;
}
});
Expand All @@ -379,14 +381,17 @@ describe('Execute: Union and intersection types', () => {

const john2 = new Person('John', [], [ liz ]);

const context = { authToken: '123abc' };

const ast = parse('{ name, friends { name } }');

expect(
await execute(schema2, ast, john2)
await execute(schema2, ast, john2, context)
).to.deep.equal({
data: { name: 'John', friends: [ { name: 'Liz' } ] }
});

expect(encounteredContext).to.equal(context);
expect(encounteredSchema).to.equal(schema2);
expect(encounteredRootValue).to.equal(john2);
});
Expand Down
52 changes: 26 additions & 26 deletions src/execution/__tests__/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ describe('Execute: Handles inputs', () => {

it('executes with complex input', async () => {
const params = { input: { a: 'foo', b: [ 'bar' ], c: 'baz' } };
const result = await execute(schema, ast, null, params);
const result = await execute(schema, ast, null, null, params);

return expect(result).to.deep.equal({
data: {
Expand All @@ -231,7 +231,7 @@ describe('Execute: Handles inputs', () => {

it('properly parses single value to list', async () => {
const params = { input: { a: 'foo', b: 'bar', c: 'baz' } };
const result = await execute(schema, ast, null, params);
const result = await execute(schema, ast, null, null, params);

return expect(result).to.deep.equal({
data: {
Expand All @@ -242,7 +242,7 @@ describe('Execute: Handles inputs', () => {

it('executes with complex scalar input', async () => {
const params = { input: { c: 'foo', d: 'SerializedValue' } };
const result = await execute(schema, ast, null, params);
const result = await execute(schema, ast, null, null, params);

return expect(result).to.deep.equal({
data: {
Expand All @@ -256,7 +256,7 @@ describe('Execute: Handles inputs', () => {

let caughtError;
try {
execute(schema, ast, null, params);
execute(schema, ast, null, null, params);
} catch (error) {
caughtError = error;
}
Expand All @@ -275,7 +275,7 @@ describe('Execute: Handles inputs', () => {

let caughtError;
try {
execute(schema, ast, null, params);
execute(schema, ast, null, null, params);
} catch (error) {
caughtError = error;
}
Expand All @@ -293,7 +293,7 @@ describe('Execute: Handles inputs', () => {

let caughtError;
try {
execute(schema, ast, null, params);
execute(schema, ast, null, null, params);
} catch (error) {
caughtError = error;
}
Expand All @@ -317,7 +317,7 @@ describe('Execute: Handles inputs', () => {

let caughtError;
try {
execute(schema, nestedAst, null, params);
execute(schema, nestedAst, null, null, params);
} catch (error) {
caughtError = error;
}
Expand All @@ -339,7 +339,7 @@ describe('Execute: Handles inputs', () => {

let caughtError;
try {
execute(schema, ast, null, params);
execute(schema, ast, null, null, params);
} catch (error) {
caughtError = error;
}
Expand Down Expand Up @@ -411,7 +411,7 @@ describe('Execute: Handles inputs', () => {
const ast = parse(doc);

return expect(
await execute(schema, ast, null, { value: null })
await execute(schema, ast, null, null, { value: null })
).to.deep.equal({
data: {
fieldWithNullableStringInput: null
Expand All @@ -428,7 +428,7 @@ describe('Execute: Handles inputs', () => {
const ast = parse(doc);

return expect(
await execute(schema, ast, null, { value: 'a' })
await execute(schema, ast, null, null, { value: 'a' })
).to.deep.equal({
data: {
fieldWithNullableStringInput: '"a"'
Expand Down Expand Up @@ -484,7 +484,7 @@ describe('Execute: Handles inputs', () => {

let caughtError;
try {
execute(schema, ast, null, { value: null });
execute(schema, ast, null, null, { value: null });
} catch (error) {
caughtError = error;
}
Expand All @@ -505,7 +505,7 @@ describe('Execute: Handles inputs', () => {
const ast = parse(doc);

return expect(
await execute(schema, ast, null, { value: 'a' })
await execute(schema, ast, null, null, { value: 'a' })
).to.deep.equal({
data: {
fieldWithNonNullableStringInput: '"a"'
Expand Down Expand Up @@ -554,7 +554,7 @@ describe('Execute: Handles inputs', () => {
const ast = parse(doc);

return expect(
await execute(schema, ast, null, { input: null })
await execute(schema, ast, null, null, { input: null })
).to.deep.equal({
data: {
list: null
Expand All @@ -571,7 +571,7 @@ describe('Execute: Handles inputs', () => {
const ast = parse(doc);

return expect(
await execute(schema, ast, null, { input: [ 'A' ] })
await execute(schema, ast, null, null, { input: [ 'A' ] })
).to.deep.equal({
data: {
list: '["A"]'
Expand All @@ -588,7 +588,7 @@ describe('Execute: Handles inputs', () => {
const ast = parse(doc);

return expect(
await execute(schema, ast, null, { input: [ 'A', null, 'B' ] })
await execute(schema, ast, null, null, { input: [ 'A', null, 'B' ] })
).to.deep.equal({
data: {
list: '["A",null,"B"]'
Expand All @@ -606,7 +606,7 @@ describe('Execute: Handles inputs', () => {

let caughtError;
try {
execute(schema, ast, null, { input: null });
execute(schema, ast, null, null, { input: null });
} catch (error) {
caughtError = error;
}
Expand All @@ -627,7 +627,7 @@ describe('Execute: Handles inputs', () => {
const ast = parse(doc);

return expect(
await execute(schema, ast, null, { input: [ 'A' ] })
await execute(schema, ast, null, null, { input: [ 'A' ] })
).to.deep.equal({
data: {
nnList: '["A"]'
Expand All @@ -644,7 +644,7 @@ describe('Execute: Handles inputs', () => {
const ast = parse(doc);

return expect(
await execute(schema, ast, null, { input: [ 'A', null, 'B' ] })
await execute(schema, ast, null, null, { input: [ 'A', null, 'B' ] })
).to.deep.equal({
data: {
nnList: '["A",null,"B"]'
Expand All @@ -661,7 +661,7 @@ describe('Execute: Handles inputs', () => {
const ast = parse(doc);

return expect(
await execute(schema, ast, null, { input: null })
await execute(schema, ast, null, null, { input: null })
).to.deep.equal({
data: {
listNN: null
Expand All @@ -678,7 +678,7 @@ describe('Execute: Handles inputs', () => {
const ast = parse(doc);

return expect(
await execute(schema, ast, null, { input: [ 'A' ] })
await execute(schema, ast, null, null, { input: [ 'A' ] })
).to.deep.equal({
data: {
listNN: '["A"]'
Expand All @@ -697,7 +697,7 @@ describe('Execute: Handles inputs', () => {

let caughtError;
try {
execute(schema, ast, null, vars);
execute(schema, ast, null, null, vars);
} catch (error) {
caughtError = error;
}
Expand All @@ -720,7 +720,7 @@ describe('Execute: Handles inputs', () => {

let caughtError;
try {
execute(schema, ast, null, { input: null });
execute(schema, ast, null, null, { input: null });
} catch (error) {
caughtError = error;
}
Expand All @@ -741,7 +741,7 @@ describe('Execute: Handles inputs', () => {
const ast = parse(doc);

return expect(
await execute(schema, ast, null, { input: [ 'A' ] })
await execute(schema, ast, null, null, { input: [ 'A' ] })
).to.deep.equal({
data: {
nnListNN: '["A"]'
Expand All @@ -760,7 +760,7 @@ describe('Execute: Handles inputs', () => {

let caughtError;
try {
execute(schema, ast, null, vars);
execute(schema, ast, null, null, vars);
} catch (error) {
caughtError = error;
}
Expand All @@ -784,7 +784,7 @@ describe('Execute: Handles inputs', () => {

let caughtError;
try {
execute(schema, ast, null, vars);
execute(schema, ast, null, null, vars);
} catch (error) {
caughtError = error;
}
Expand All @@ -808,7 +808,7 @@ describe('Execute: Handles inputs', () => {

let caughtError;
try {
execute(schema, ast, null, vars);
execute(schema, ast, null, null, vars);
} catch (error) {
caughtError = error;
}
Expand Down
Loading