Skip to content

Commit 041e4ef

Browse files
committed
test: add shallow check
Related #7
1 parent 8947d87 commit 041e4ef

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/__tests__/composeWithJson-test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,60 @@ describe('composeWithJson', () => {
151151
},
152152
});
153153
});
154+
155+
it('check shallow objects', async () => {
156+
const restApiResponse = {
157+
title: 'A New Hope',
158+
producer: {
159+
name: 'Gary Kurtz, Rick McCallum',
160+
},
161+
};
162+
163+
const FilmTC = composeWithJson('FilmCustom', restApiResponse);
164+
165+
expect(FilmTC.getFieldTC('producer').getTypeName()).toBe('FilmCustom_Producer');
166+
expect(FilmTC.getFieldTC('producer').getFieldNames()).toEqual(['name']);
167+
expect(
168+
FilmTC.getFieldTC('producer')
169+
.getFieldType('name')
170+
.toString()
171+
).toBe('String');
172+
173+
const schema1 = new GraphQLSchema({
174+
query: new GraphQLObjectType({
175+
name: 'Query',
176+
fields: {
177+
film: {
178+
type: FilmTC.getType(),
179+
resolve: () => {
180+
return restApiResponse;
181+
},
182+
},
183+
},
184+
}),
185+
});
186+
187+
const res = await graphql.graphql(
188+
schema1,
189+
`{
190+
film {
191+
title
192+
producer {
193+
name
194+
}
195+
}
196+
}`
197+
);
198+
199+
expect(res).toEqual({
200+
data: {
201+
film: {
202+
title: 'A New Hope',
203+
producer: {
204+
name: 'Gary Kurtz, Rick McCallum',
205+
},
206+
},
207+
},
208+
});
209+
});
154210
});

0 commit comments

Comments
 (0)