22 GraphQLBoolean ,
33 GraphQLID ,
44 GraphQLInt ,
5- GraphQLList ,
65 GraphQLNonNull ,
76 GraphQLObjectType ,
87 GraphQLString ,
@@ -36,31 +35,34 @@ const data = {
3635 ] ,
3736} ;
3837
38+ const UserType = new GraphQLObjectType ( {
39+ name : 'User' ,
40+ fields : {
41+ id : { type : new GraphQLNonNull ( GraphQLID ) } ,
42+ name : { type : new GraphQLNonNull ( GraphQLString ) } ,
43+ } ,
44+ } ) ;
45+
3946const PostType = new GraphQLObjectType ( {
4047 name : 'Post' ,
4148 fields : {
4249 id : { type : new GraphQLNonNull ( GraphQLID ) } ,
4350 title : { type : new GraphQLNonNull ( GraphQLString ) } ,
4451 views : { type : new GraphQLNonNull ( GraphQLInt ) } ,
4552 user_id : { type : new GraphQLNonNull ( GraphQLID ) } ,
46- } ,
47- } ) ;
48- const UserType = new GraphQLObjectType ( {
49- name : 'User' ,
50- fields : {
51- id : { type : new GraphQLNonNull ( GraphQLID ) } ,
52- name : { type : new GraphQLNonNull ( GraphQLString ) } ,
53+ User : { type : UserType } ,
5354 } ,
5455} ) ;
5556
57+ /*
5658const ListMetadataType = new GraphQLObjectType({
5759 name: 'ListMetadata',
5860 fields: {
5961 count: { type: GraphQLInt },
6062 },
6163});
6264
63- const QueryType = new GraphQLObjectType ( { // eslint-disable-line
65+ const QueryType = new GraphQLObjectType({
6466 name: 'Query',
6567 fields: {
6668 getPost: {
@@ -97,13 +99,18 @@ const QueryType = new GraphQLObjectType({ // eslint-disable-line
9799 },
98100 },
99101});
102+ */
100103
101104test ( 'creates one type per data type' , ( ) => {
102105 const typeMap = getSchemaFromData ( data ) . getTypeMap ( ) ;
103106 expect ( typeMap [ 'Post' ] . name ) . toEqual ( PostType . name ) ;
104- expect ( typeMap [ 'Post' ] . fields ) . toEqual ( PostType . fields ) ;
107+ expect ( Object . keys ( typeMap [ 'Post' ] . getFields ( ) ) ) . toEqual (
108+ Object . keys ( PostType . getFields ( ) ) ,
109+ ) ;
105110 expect ( typeMap [ 'User' ] . name ) . toEqual ( UserType . name ) ;
106- expect ( typeMap [ 'User' ] . fields ) . toEqual ( UserType . fields ) ;
111+ expect ( Object . keys ( typeMap [ 'User' ] . getFields ( ) ) ) . toEqual (
112+ Object . keys ( UserType . getFields ( ) ) ,
113+ ) ;
107114} ) ;
108115
109116test ( 'creates three query fields per data type' , ( ) => {
@@ -117,7 +124,7 @@ test('creates three query fields per data type', () => {
117124 type : new GraphQLNonNull ( GraphQLID ) ,
118125 } ,
119126 ] ) ;
120- expect ( queries [ 'allPosts' ] . type ) . toMatchObject ( new GraphQLList ( PostType ) ) ;
127+ expect ( queries [ 'allPosts' ] . type . toString ( ) ) . toEqual ( '[Post]' ) ;
121128 expect ( queries [ 'allPosts' ] . args ) . toEqual ( [
122129 {
123130 defaultValue : undefined ,
@@ -150,7 +157,7 @@ test('creates three query fields per data type', () => {
150157 type : GraphQLString ,
151158 } ,
152159 ] ) ;
153- expect ( queries [ '_allPostsMeta' ] . type ) . toMatchObject ( ListMetadataType ) ;
160+ expect ( queries [ '_allPostsMeta' ] . type . toString ( ) ) . toEqual ( 'ListMetadata' ) ;
154161
155162 expect ( queries [ 'User' ] . type . name ) . toEqual ( UserType . name ) ;
156163 expect ( queries [ 'User' ] . args ) . toEqual ( [
@@ -161,7 +168,7 @@ test('creates three query fields per data type', () => {
161168 type : new GraphQLNonNull ( GraphQLID ) ,
162169 } ,
163170 ] ) ;
164- expect ( queries [ 'allUsers' ] . type ) . toMatchObject ( new GraphQLList ( UserType ) ) ;
171+ expect ( queries [ 'allUsers' ] . type . toString ( ) ) . toEqual ( '[User]' ) ;
165172 expect ( queries [ 'allUsers' ] . args ) . toEqual ( [
166173 {
167174 defaultValue : undefined ,
@@ -194,7 +201,7 @@ test('creates three query fields per data type', () => {
194201 type : GraphQLString ,
195202 } ,
196203 ] ) ;
197- expect ( queries [ '_allPostsMeta' ] . type ) . toMatchObject ( ListMetadataType ) ;
204+ expect ( queries [ '_allPostsMeta' ] . type . toString ( ) ) . toEqual ( 'ListMetadata' ) ;
198205} ) ;
199206
200207test ( 'creates three mutation fields per data type' , ( ) => {
0 commit comments