Skip to content

Commit

Permalink
Merge pull request #74 from wincent/graphql-5.0-compat
Browse files Browse the repository at this point in the history
Make compatible with graphql-js v0.5.0
  • Loading branch information
wincent committed Apr 12, 2016
2 parents 84a1268 + 4ed95bd commit 784b227
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"babel-runtime": "~5.8.3"
},
"peerDependencies": {
"graphql": "~0.4.2"
"graphql": "~0.5.0"
},
"devDependencies": {
"babel": "5.8.3",
Expand All @@ -60,7 +60,7 @@
"coveralls": "2.11.8",
"eslint": "2.2.0",
"flow-bin": "0.22.1",
"graphql": "0.4.18",
"graphql": "0.5.0",
"isparta": "3.0.3",
"mocha": "2.2.5",
"sane": "1.1.3"
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/starWarsMutationTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Star Wars mutations', () => {
clientMutationId: 'abcde',
}
};
var result = await graphql(StarWarsSchema, mutation, null, params);
var result = await graphql(StarWarsSchema, mutation, null, null, params);
expect(result).to.deep.equal({ data: expected });
});
});
3 changes: 2 additions & 1 deletion src/node/__tests__/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ var queryType = new GraphQLObjectType({
});

var schema = new GraphQLSchema({
query: queryType
query: queryType,
types: [userType, photoType, postType]
});

describe('global ID fields', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/node/__tests__/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var photoData = {
};

var {nodeField, nodeInterface} = nodeDefinitions(
(id, info) => {
(id, context, info) => {
expect(info.schema).to.equal(schema);
if (userData[id]) {
return userData[id];
Expand Down Expand Up @@ -99,7 +99,8 @@ var queryType = new GraphQLObjectType({
});

var schema = new GraphQLSchema({
query: queryType
query: queryType,
types: [userType, photoType]
});

describe('Node interface and fields', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/node/__tests__/nodeasync.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ var queryType = new GraphQLObjectType({
});

var schema = new GraphQLSchema({
query: queryType
query: queryType,
types: [userType]
});

describe('Node interface and fields with async object fetcher', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/node/__tests__/plural.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var queryType = new GraphQLObjectType({
description: 'Map from a username to the user',
inputType: GraphQLString,
outputType: userType,
resolveSingleInput: (username, {rootValue: {lang}}) => ({
resolveSingleInput: (username, context, {rootValue: {lang}}) => ({
username: username,
url: 'www.facebook.com/' + username + '?lang=' + lang
})
Expand Down
10 changes: 5 additions & 5 deletions src/node/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type typeResolverFn = (object: any) => ?GraphQLObjectType |
* interface without a provided `resolveType` method.
*/
export function nodeDefinitions(
idFetcher: ((id: string, info: GraphQLResolveInfo) => any),
idFetcher: ((id: string, context: any, info: GraphQLResolveInfo) => any),
typeResolver?: ?typeResolverFn
): GraphQLNodeDefinitions {
var nodeInterface = new GraphQLInterfaceType({
Expand All @@ -69,7 +69,7 @@ export function nodeDefinitions(
description: 'The ID of an object'
}
},
resolve: (obj, {id}, info) => idFetcher(id, info)
resolve: (obj, {id}, context, info) => idFetcher(id, context, info),
};

return {nodeInterface, nodeField};
Expand Down Expand Up @@ -109,15 +109,15 @@ export function fromGlobalId(globalId: string): ResolvedGlobalId {
*/
export function globalIdField(
typeName?: ?string,
idFetcher?: (object: any, info: GraphQLResolveInfo) => string
idFetcher?: (object: any, context: any, info: GraphQLResolveInfo) => string
): GraphQLFieldConfig {
return {
name: 'id',
description: 'The ID of an object',
type: new GraphQLNonNull(GraphQLID),
resolve: (obj, args, info) => toGlobalId(
resolve: (obj, args, context, info) => toGlobalId(
typeName || info.parentType.name,
idFetcher ? idFetcher(obj, info) : obj.id
idFetcher ? idFetcher(obj, context, info) : obj.id
)
};
}
9 changes: 6 additions & 3 deletions src/node/plural.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ type PluralIdentifyingRootFieldConfig = {
argName: string,
inputType: GraphQLInputType,
outputType: GraphQLOutputType,
resolveSingleInput: (input: any, info: GraphQLResolveInfo) => ?any,
resolveSingleInput:
(input: any, context: any, info: GraphQLResolveInfo) => ?any,
description?: ?string,
};

Expand All @@ -45,10 +46,12 @@ export function pluralIdentifyingRootField(
description: config.description,
type: new GraphQLList(config.outputType),
args: inputArgs,
resolve: (obj, args, info) => {
resolve: (obj, args, context, info) => {
var inputs = args[config.argName];
return Promise.all(inputs.map(
input => Promise.resolve(config.resolveSingleInput(input, info))
input => Promise.resolve(
config.resolveSingleInput(input, context, info)
)
));
}
};
Expand Down

0 comments on commit 784b227

Please sign in to comment.