Skip to content

Commit 373f2da

Browse files
committed
Update to support [email protected]
1 parent 4e32628 commit 373f2da

File tree

6 files changed

+39
-32
lines changed

6 files changed

+39
-32
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"babel-runtime": "^6.9.0"
4343
},
4444
"peerDependencies": {
45-
"graphql": "^0.5.0 || ^0.6.0 || ^0.7.0"
45+
"graphql": "^0.5.0 || ^0.6.0 || ^0.7.0 || ^0.8.0-b"
4646
},
4747
"devDependencies": {
4848
"babel-cli": "6.18.0",
@@ -75,7 +75,7 @@
7575
"eslint-plugin-babel": "3.3.0",
7676
"eslint-plugin-flowtype": "2.25.0",
7777
"flow-bin": "0.35.0",
78-
"graphql": "0.7.0",
78+
"graphql": "0.8.2",
7979
"isparta": "4.0.0",
8080
"mocha": "3.1.2",
8181
"sane": "1.4.1"

src/connection/connection.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type {
2121
GraphQLFieldConfigArgumentMap,
2222
GraphQLFieldConfigMap,
2323
GraphQLFieldResolver,
24+
Thunk,
2425
} from 'graphql';
2526

2627
/**
@@ -63,16 +64,16 @@ type ConnectionConfig = {
6364
nodeType: GraphQLObjectType,
6465
resolveNode?: ?GraphQLFieldResolver<*, *>,
6566
resolveCursor?: ?GraphQLFieldResolver<*, *>,
66-
edgeFields?: ?(() => GraphQLFieldConfigMap) | ?GraphQLFieldConfigMap,
67-
connectionFields?: ?(() => GraphQLFieldConfigMap) | ?GraphQLFieldConfigMap,
67+
edgeFields?: ?Thunk<GraphQLFieldConfigMap<*, *>>,
68+
connectionFields?: ?Thunk<GraphQLFieldConfigMap<*, *>>,
6869
};
6970

7071
type GraphQLConnectionDefinitions = {
7172
edgeType: GraphQLObjectType,
7273
connectionType: GraphQLObjectType
7374
};
7475

75-
function resolveMaybeThunk<T>(thingOrThunk: T | () => T): T {
76+
function resolveMaybeThunk<T>(thingOrThunk: Thunk<T>): T {
7677
return typeof thingOrThunk === 'function' ? thingOrThunk() : thingOrThunk;
7778
}
7879

src/mutation/__tests__/mutation.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,17 @@ describe('mutationWithClientMutationId()', () => {
9999
}
100100
}
101101
`;
102-
const result = await graphql(schema, query);
103-
expect(result.errors.length).to.equal(1);
104-
expect(result.errors[0].message).to.equal(
105-
'Field "simpleMutation" argument "input" of type "SimpleMutationInput!" ' +
106-
'is required but not provided.'
107-
);
102+
expect(await graphql(schema, query)).to.deep.equal({
103+
errors: [
104+
{
105+
message:
106+
'Field "simpleMutation" argument "input" of type ' +
107+
'"SimpleMutationInput!" is required but not provided.',
108+
locations: [ { line: 3, column: 9 } ],
109+
path: undefined
110+
}
111+
]
112+
});
108113
});
109114

110115
it('returns the same client mutation ID', async () => {

src/mutation/mutation.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import {
1717

1818
import type {
1919
GraphQLFieldConfig,
20-
InputObjectConfigFieldMap,
20+
GraphQLInputFieldConfigMap,
2121
GraphQLFieldConfigMap,
22-
GraphQLResolveInfo
22+
GraphQLResolveInfo,
23+
Thunk,
2324
} from 'graphql';
2425

2526
type mutationFn = (
@@ -28,7 +29,7 @@ type mutationFn = (
2829
info: GraphQLResolveInfo
2930
) => Promise<any> | any;
3031

31-
function resolveMaybeThunk<T>(thingOrThunk: T | () => T): T {
32+
function resolveMaybeThunk<T>(thingOrThunk: Thunk<T>): T {
3233
return typeof thingOrThunk === 'function' ? thingOrThunk() : thingOrThunk;
3334
}
3435

@@ -48,8 +49,8 @@ function resolveMaybeThunk<T>(thingOrThunk: T | () => T): T {
4849
*/
4950
type MutationConfig = {
5051
name: string,
51-
inputFields: InputObjectConfigFieldMap,
52-
outputFields: GraphQLFieldConfigMap,
52+
inputFields: Thunk<GraphQLInputFieldConfigMap>,
53+
outputFields: Thunk<GraphQLFieldConfigMap<*, *>>,
5354
mutateAndGetPayload: mutationFn,
5455
};
5556

@@ -59,7 +60,7 @@ type MutationConfig = {
5960
*/
6061
export function mutationWithClientMutationId(
6162
config: MutationConfig
62-
): GraphQLFieldConfig {
63+
): GraphQLFieldConfig<*, *> {
6364
const { name, inputFields, outputFields, mutateAndGetPayload } = config;
6465
const augmentedInputFields = () => ({
6566
...resolveMaybeThunk(inputFields),

src/node/node.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import {
1616

1717
import type {
1818
GraphQLFieldConfig,
19-
GraphQLObjectType,
20-
GraphQLResolveInfo
19+
GraphQLResolveInfo,
20+
GraphQLTypeResolver
2121
} from 'graphql';
2222

2323
import {
@@ -27,13 +27,9 @@ import {
2727

2828
type GraphQLNodeDefinitions = {
2929
nodeInterface: GraphQLInterfaceType,
30-
nodeField: GraphQLFieldConfig
30+
nodeField: GraphQLFieldConfig<*, *>
3131
};
3232

33-
type typeResolverFn = (
34-
object: any
35-
) => ?GraphQLObjectType | ?Promise<GraphQLObjectType>;
36-
3733
/**
3834
* Given a function to map from an ID to an underlying object, and a function
3935
* to map from an underlying object to the concrete GraphQLObjectType it
@@ -44,9 +40,9 @@ type typeResolverFn = (
4440
* handled with the `isTypeOf` method on object types, as with any GraphQL
4541
* interface without a provided `resolveType` method.
4642
*/
47-
export function nodeDefinitions(
48-
idFetcher: ((id: string, context: any, info: GraphQLResolveInfo) => any),
49-
typeResolver?: ?typeResolverFn
43+
export function nodeDefinitions<TContext>(
44+
idFetcher: ((id: string, context: TContext, info: GraphQLResolveInfo) => any),
45+
typeResolver?: ?GraphQLTypeResolver<*, TContext>
5046
): GraphQLNodeDefinitions {
5147
const nodeInterface = new GraphQLInterfaceType({
5248
name: 'Node',
@@ -70,10 +66,10 @@ export function nodeDefinitions(
7066
description: 'The ID of an object'
7167
}
7268
},
73-
resolve: (obj, {id}, context, info) => idFetcher(id, context, info),
69+
resolve: (obj, { id }, context, info) => idFetcher(id, context, info),
7470
};
7571

76-
return {nodeInterface, nodeField};
72+
return { nodeInterface, nodeField };
7773
}
7874

7975
type ResolvedGlobalId = {
@@ -111,7 +107,7 @@ export function fromGlobalId(globalId: string): ResolvedGlobalId {
111107
export function globalIdField(
112108
typeName?: ?string,
113109
idFetcher?: (object: any, context: any, info: GraphQLResolveInfo) => string
114-
): GraphQLFieldConfig {
110+
): GraphQLFieldConfig<*, *> {
115111
return {
116112
name: 'id',
117113
description: 'The ID of an object',

src/node/plural.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ type PluralIdentifyingRootFieldConfig = {
3434

3535
export function pluralIdentifyingRootField(
3636
config: PluralIdentifyingRootFieldConfig
37-
): GraphQLFieldConfig {
37+
): GraphQLFieldConfig<*, *> {
3838
const inputArgs = {};
39+
let inputType = config.inputType;
40+
if (inputType instanceof GraphQLNonNull) {
41+
inputType = inputType.ofType;
42+
}
3943
inputArgs[config.argName] = {
4044
type: new GraphQLNonNull(
4145
new GraphQLList(
4246
new GraphQLNonNull(
43-
config.inputType
47+
inputType
4448
)
4549
)
4650
)

0 commit comments

Comments
 (0)