11/* @flow */
22
3- import { TypeComposer } from 'graphql-compose' ;
3+ import { ObjectTypeComposer , schemaComposer } from 'graphql-compose' ;
44import {
55 GraphQLInterfaceType ,
66 GraphQLSchema ,
77 GraphQLNonNull ,
88 graphql ,
99} from 'graphql-compose/lib/graphql' ;
1010import { composeWithRelay } from '../composeWithRelay' ;
11- import { userTypeComposer } from '../__mocks__/userTypeComposer' ;
12- import { rootQueryTypeComposer } from '../__mocks__/rootQueryTypeComposer' ;
13- import { rootMutationTypeComposer } from '../__mocks__/rootMutationTypeComposer' ;
11+ import { userTC } from '../__mocks__/userTC' ;
1412import { toGlobalId } from '../globalId' ;
1513
1614describe ( 'composeWithRelay' , ( ) => {
17- const userComposer = composeWithRelay ( userTypeComposer ) ;
18- const rootQueryComposer = composeWithRelay ( rootQueryTypeComposer ) ;
19- const rootMutationComposer = composeWithRelay ( rootMutationTypeComposer ) ;
15+ const userComposer = composeWithRelay ( userTC ) ;
16+ const queryTC = composeWithRelay ( schemaComposer . Query ) ;
17+ const mutationTC = composeWithRelay ( schemaComposer . Mutation ) ;
2018
2119 describe ( 'basic checks' , ( ) => {
22- it ( 'should return TypeComposer ' , ( ) => {
23- expect ( userComposer ) . toBeInstanceOf ( TypeComposer ) ;
20+ it ( 'should return ObjectTypeComposer ' , ( ) => {
21+ expect ( userComposer ) . toBeInstanceOf ( ObjectTypeComposer ) ;
2422 } ) ;
2523
26- it ( 'should throw error if got a not TypeComposer ' , ( ) => {
24+ it ( 'should throw error if got a not ObjectTypeComposer ' , ( ) => {
2725 expect ( ( ) => composeWithRelay ( ( 123 : any ) ) ) . toThrowError (
28- 'should provide TypeComposer instance'
26+ 'should provide ObjectTypeComposer instance'
2927 ) ;
3028 } ) ;
3129
32- it ( 'should throw error if TypeComposer without recordIdFn' , ( ) => {
33- const tc = userTypeComposer . clone ( 'AnotherUserType2' ) ;
30+ it ( 'should throw error if ObjectTypeComposer without recordIdFn' , ( ) => {
31+ const tc = userTC . clone ( 'AnotherUserType2' ) ;
3432 delete tc . gqType . _gqcGetRecordIdFn ;
3533 expect ( ( ) => composeWithRelay ( tc ) ) . toThrowError ( 'should have recordIdFn' ) ;
3634 } ) ;
3735
3836 it ( 'should thow error if typeComposer does not have findById resolver' , ( ) => {
39- const tc = userTypeComposer . clone ( 'AnotherUserType' ) ;
37+ const tc = userTC . clone ( 'AnotherUserType' ) ;
4038 tc . removeResolver ( 'findById' ) ;
4139 expect ( ( ) => composeWithRelay ( tc ) ) . toThrowError (
4240 "does not have resolver with name 'findById'"
@@ -46,7 +44,7 @@ describe('composeWithRelay', () => {
4644
4745 describe ( 'when pass RootQuery type composer' , ( ) => {
4846 it ( 'should add `node` field to RootQuery' , ( ) => {
49- const nodeField : any = rootQueryComposer . getField ( 'node' ) ;
47+ const nodeField : any = queryTC . getField ( 'node' ) ;
5048 expect ( nodeField . type ) . toBeInstanceOf ( GraphQLInterfaceType ) ;
5149 expect ( nodeField . type . name ) . toBe ( 'Node' ) ;
5250 } ) ;
@@ -64,9 +62,9 @@ describe('composeWithRelay', () => {
6462 } ) ;
6563
6664 it ( 'should resolve globalId in `user.id` field' , async ( ) => {
67- rootQueryTypeComposer . setField ( 'user' , userTypeComposer . getResolver ( 'findById' ) ) ;
65+ queryTC . setField ( 'user' , userTC . getResolver ( 'findById' ) ) ;
6866 const schema = new GraphQLSchema ( {
69- query : rootQueryTypeComposer . getType ( ) ,
67+ query : queryTC . getType ( ) ,
7068 } ) ;
7169 const query = `{
7270 user(_id: 1) {
@@ -80,9 +78,9 @@ describe('composeWithRelay', () => {
8078 } ) ;
8179
8280 it ( 'should resolve globalId in `node.id` field' , async ( ) => {
83- rootQueryTypeComposer . setField ( 'user' , userTypeComposer . getResolver ( 'findById' ) ) ;
81+ queryTC . setField ( 'user' , userTC . getResolver ( 'findById' ) ) ;
8482 const schema = new GraphQLSchema ( {
85- query : rootQueryTypeComposer . getType ( ) ,
83+ query : queryTC . getType ( ) ,
8684 } ) ;
8785 const query = `{
8886 node(id: "${ toGlobalId ( 'User' , 1 ) } ") {
@@ -99,10 +97,10 @@ describe('composeWithRelay', () => {
9997 } ) ;
10098
10199 it ( 'should passthru clientMutationId in mutations' , async ( ) => {
102- rootMutationComposer . setField ( 'createUser' , userTypeComposer . getResolver ( 'createOne' ) ) ;
100+ mutationTC . setField ( 'createUser' , userTC . getResolver ( 'createOne' ) ) ;
103101 const schema = new GraphQLSchema ( {
104- query : rootQueryTypeComposer . getType ( ) ,
105- mutation : rootMutationComposer . getType ( ) ,
102+ query : queryTC . getType ( ) ,
103+ mutation : mutationTC . getType ( ) ,
106104 } ) ;
107105 const query = `mutation {
108106 createUser(input: { name: "Ok", clientMutationId: "123" }) {
0 commit comments