@@ -58,8 +58,69 @@ describe("FileSchemaProvider", () => {
5858 dir = dirPath = undefined ;
5959 } ) ;
6060
61- it ( "finds and loads sdl from graphql file" , async ( ) => {
62- const writtenSDL = `
61+ describe ( "resolveFederatedServiceSDL" , ( ) => {
62+ it ( "finds and loads sdl from graphql file for a federated service" , async ( ) => {
63+ writeFilesToDir ( dir , {
64+ "schema.graphql" : `
65+ extend type Query {
66+ myProduct: Product
67+ }
68+
69+ type Product @key(fields: "id") {
70+ id: ID
71+ sku: ID
72+ name: String
73+ }
74+ `
75+ } ) ;
76+
77+ const provider = new FileSchemaProvider ( {
78+ path : dir + "/schema.graphql"
79+ } ) ;
80+ const sdl = await provider . resolveFederatedServiceSDL ( ) ;
81+ expect ( sdl ) . toMatchInlineSnapshot ;
82+ } ) ;
83+
84+ it ( "finds and loads sdl from multiple graphql files for a federated service" , async ( ) => {
85+ writeFilesToDir ( dir , {
86+ "schema.graphql" : `
87+ extend type Query {
88+ myProduct: Product
89+ }
90+
91+ type Product @key(fields: "id") {
92+ id: ID
93+ sku: ID
94+ name: String
95+ }` ,
96+ "schema2.graphql" : `
97+ extend type Product {
98+ weight: Float
99+ }`
100+ } ) ;
101+
102+ const provider = new FileSchemaProvider ( {
103+ paths : [ dir + "/schema.graphql" , dir + "/schema2.graphql" ]
104+ } ) ;
105+ const sdl = await provider . resolveFederatedServiceSDL ( ) ;
106+ expect ( sdl ) . toMatchInlineSnapshot ( `
107+ "type Product @key(fields: \\"id\\") {
108+ id: ID
109+ sku: ID
110+ name: String
111+ weight: Float
112+ }
113+
114+ extend type Query {
115+ myProduct: Product
116+ }
117+ "
118+ ` ) ;
119+ } ) ;
120+
121+ it ( "errors when sdl file is not a graphql file" , async ( ) => {
122+ const toWrite = `
123+ module.exports = \`
63124 extend type Query {
64125 myProduct: Product
65126 }
@@ -68,41 +129,19 @@ describe("FileSchemaProvider", () => {
68129 id: ID
69130 sku: ID
70131 name: string
71- }
132+ }\`
72133 ` ;
73- writeFilesToDir ( dir , {
74- "schema.graphql " : writtenSDL
75- } ) ;
134+ writeFilesToDir ( dir , {
135+ "schema.js " : toWrite
136+ } ) ;
76137
77- const provider = new FileSchemaProvider ( { path : dir + "/schema.graphql" } ) ;
78- const sdl = await provider . resolveFederatedServiceSDL ( ) ;
79- expect ( sdl ) . toEqual ( writtenSDL ) ;
80- } ) ;
138+ // noop -- just spy on and silence the error
139+ const errorSpy = jest . spyOn ( Debug , "error" ) ;
140+ errorSpy . mockImplementation ( ( ) => { } ) ;
81141
82- it ( "errors when sdl file is not a graphql file" , async ( ) => {
83- const toWrite = `
84- module.exports = \`
85- extend type Query {
86- myProduct: Product
87- }
88-
89- type Product @key(fields: "id") {
90- id: ID
91- sku: ID
92- name: string
93- }\`
94- ` ;
95- writeFilesToDir ( dir , {
96- "schema.js" : toWrite
142+ const provider = new FileSchemaProvider ( { path : dir + "/schema.js" } ) ;
143+ const sdl = await provider . resolveFederatedServiceSDL ( ) ;
144+ expect ( errorSpy ) . toBeCalledTimes ( 2 ) ;
97145 } ) ;
98-
99- const errorSpy = jest . spyOn ( Debug , "error" ) ;
100-
101- // noop -- just silence the error
102- errorSpy . mockImplementationOnce ( ( ) => { } ) ;
103-
104- const provider = new FileSchemaProvider ( { path : dir + "/schema.js" } ) ;
105- const sdl = await provider . resolveFederatedServiceSDL ( ) ;
106- expect ( errorSpy ) . toBeCalledTimes ( 1 ) ;
107146 } ) ;
108147} ) ;
0 commit comments