Skip to content

Commit aa754f6

Browse files
committed
Pass resolve info to pluralIdentifyingRootField's resolveSingleInput.
1 parent 649c3ed commit aa754f6

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/node/__tests__/plural.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ var queryType = new GraphQLObjectType({
4242
description: 'Map from a username to the user',
4343
inputType: GraphQLString,
4444
outputType: userType,
45-
resolveSingleInput: (username) => ({
45+
resolveSingleInput: (username, {rootValue: {lang}}) => ({
4646
username: username,
47-
url: 'www.facebook.com/' + username
47+
url: 'www.facebook.com/' + username + '?lang=' + lang
4848
})
4949
})
5050
})
@@ -54,6 +54,8 @@ var schema = new GraphQLSchema({
5454
query: queryType
5555
});
5656

57+
var rootVal = {lang: 'en'};
58+
5759
describe('pluralIdentifyingRootField()', () => {
5860
it('allows fetching', () => {
5961
var query = `{
@@ -66,20 +68,20 @@ describe('pluralIdentifyingRootField()', () => {
6668
usernames: [
6769
{
6870
username: 'dschafer',
69-
url: 'www.facebook.com/dschafer'
71+
url: 'www.facebook.com/dschafer?lang=en'
7072
},
7173
{
7274
username: 'leebyron',
73-
url: 'www.facebook.com/leebyron'
75+
url: 'www.facebook.com/leebyron?lang=en'
7476
},
7577
{
7678
username: 'schrockn',
77-
url: 'www.facebook.com/schrockn'
79+
url: 'www.facebook.com/schrockn?lang=en'
7880
},
7981
]
8082
};
8183

82-
return expect(graphql(schema, query)).to.become({data: expected});
84+
return expect(graphql(schema, query, rootVal)).to.become({data: expected});
8385
});
8486

8587
it('correctly introspects', () => {

src/node/plural.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ import type {
1717
GraphQLFieldConfig,
1818
GraphQLInputType,
1919
GraphQLOutputType,
20+
GraphQLResolveInfo
2021
} from 'graphql';
2122

2223
type PluralIdentifyingRootFieldConfig = {
2324
argName: string,
2425
inputType: GraphQLInputType,
2526
outputType: GraphQLOutputType,
26-
resolveSingleInput: (input: any) => ?any,
27+
resolveSingleInput: (input: any, info: GraphQLResolveInfo) => ?any,
2728
description?: ?string,
2829
};
2930

@@ -44,10 +45,10 @@ export function pluralIdentifyingRootField(
4445
description: config.description,
4546
type: new GraphQLList(config.outputType),
4647
args: inputArgs,
47-
resolve: (obj, args) => {
48+
resolve: (obj, args, info) => {
4849
var inputs = args[config.argName];
4950
return Promise.all(inputs.map(
50-
input => Promise.resolve(config.resolveSingleInput(input))
51+
input => Promise.resolve(config.resolveSingleInput(input, info))
5152
));
5253
}
5354
};

0 commit comments

Comments
 (0)