@@ -47,7 +47,7 @@ const photoData = {
4747 } ,
4848} ;
4949
50- const { nodeField, nodeInterface } = nodeDefinitions (
50+ const { nodeField, nodesField , nodeInterface } = nodeDefinitions (
5151 ( id , context , info ) => {
5252 expect ( info . schema ) . to . equal ( schema ) ;
5353 if ( userData [ id ] ) {
@@ -96,7 +96,8 @@ const photoType = new GraphQLObjectType({
9696const queryType = new GraphQLObjectType ( {
9797 name : 'Query' ,
9898 fields : ( ) => ( {
99- node : nodeField
99+ node : nodeField ,
100+ nodes : nodesField
100101 } )
101102} ) ;
102103
@@ -123,6 +124,27 @@ describe('Node interface and fields', () => {
123124 } ) ;
124125 } ) ;
125126
127+ it ( 'gets the correct IDs for users' , async ( ) => {
128+ const query = `{
129+ nodes(ids: ["1", "2"]) {
130+ id
131+ }
132+ }` ;
133+
134+ expect ( await graphql ( schema , query ) ) . to . deep . equal ( {
135+ data : {
136+ nodes : [
137+ {
138+ id : '1'
139+ } ,
140+ {
141+ id : '2'
142+ }
143+ ]
144+ }
145+ } ) ;
146+ } ) ;
147+
126148 it ( 'gets the correct ID for photos' , async ( ) => {
127149 const query = `{
128150 node(id: "4") {
@@ -139,6 +161,48 @@ describe('Node interface and fields', () => {
139161 } ) ;
140162 } ) ;
141163
164+ it ( 'gets the correct IDs for photos' , async ( ) => {
165+ const query = `{
166+ nodes(ids: ["3", "4"]) {
167+ id
168+ }
169+ }` ;
170+
171+ expect ( await graphql ( schema , query ) ) . to . deep . equal ( {
172+ data : {
173+ nodes : [
174+ {
175+ id : '3'
176+ } ,
177+ {
178+ id : '4'
179+ }
180+ ]
181+ }
182+ } ) ;
183+ } ) ;
184+
185+ it ( 'gets the correct IDs for multiple types' , async ( ) => {
186+ const query = `{
187+ nodes(ids: ["1", "3"]) {
188+ id
189+ }
190+ }` ;
191+
192+ expect ( await graphql ( schema , query ) ) . to . deep . equal ( {
193+ data : {
194+ nodes : [
195+ {
196+ id : '1'
197+ } ,
198+ {
199+ id : '3'
200+ }
201+ ]
202+ }
203+ } ) ;
204+ } ) ;
205+
142206 it ( 'gets the correct name for users' , async ( ) => {
143207 const query = `{
144208 node(id: "1") {
@@ -247,6 +311,25 @@ describe('Node interface and fields', () => {
247311 }
248312 } ) ;
249313 } ) ;
314+
315+ it ( 'returns nulls for bad IDs' , async ( ) => {
316+ const query = `{
317+ nodes(ids: ["3", "5"]) {
318+ id
319+ }
320+ }` ;
321+
322+ return expect ( await graphql ( schema , query ) ) . to . deep . equal ( {
323+ data : {
324+ nodes : [
325+ {
326+ id : '3'
327+ } ,
328+ null
329+ ]
330+ }
331+ } ) ;
332+ } ) ;
250333 } ) ;
251334
252335 describe ( 'introspection' , ( ) => {
@@ -290,7 +373,7 @@ describe('Node interface and fields', () => {
290373 } ) ;
291374 } ) ;
292375
293- it ( 'has correct node root field ' , async ( ) => {
376+ it ( 'has correct node and nodes root fields ' , async ( ) => {
294377 const query = `{
295378 __schema {
296379 queryType {
@@ -338,6 +421,25 @@ describe('Node interface and fields', () => {
338421 }
339422 }
340423 ]
424+ } ,
425+ {
426+ name : 'nodes' ,
427+ type : {
428+ name : null ,
429+ kind : 'NON_NULL'
430+ } ,
431+ args : [
432+ {
433+ name : 'ids' ,
434+ type : {
435+ kind : 'NON_NULL' ,
436+ ofType : {
437+ name : null ,
438+ kind : 'LIST'
439+ }
440+ }
441+ }
442+ ]
341443 }
342444 ]
343445 }
0 commit comments