@@ -370,4 +370,84 @@ class FastSchemaGeneratorTest extends Specification {
370370 schema != null
371371 }
372372
373+ def " schema directives from schema definition and schema extensions match standard SchemaGenerator" () {
374+ given :
375+ def sdl = '''
376+ directive @link(url: String!, purpose: Purpose, opts: LinkOpts) repeatable on SCHEMA
377+ directive @owner(team: String!) on SCHEMA
378+
379+ enum Purpose { SECURITY EXECUTION }
380+ input LinkOpts { strict: Boolean }
381+
382+ schema @link(url: "https://a.dev", purpose: SECURITY, opts: { strict: true }) {
383+ query: Query
384+ }
385+
386+ extend schema @owner(team: "graph") @link(url: "https://b.dev")
387+
388+ type Query { hello: String }
389+ '''
390+ def registry = new SchemaParser (). parse(sdl)
391+
392+ when :
393+ def standardSchema = new SchemaGenerator (). makeExecutableSchema(registry, RuntimeWiring . MOCKED_WIRING )
394+ def fastSchema = new FastSchemaGenerator (). makeExecutableSchema(registry, RuntimeWiring . MOCKED_WIRING )
395+
396+ then :
397+ fastSchema. schemaAppliedDirectives. collect { it. name } == [" link" , " owner" , " link" ]
398+ fastSchema. schemaAppliedDirectives. collect { it. name } == standardSchema. schemaAppliedDirectives. collect { it. name }
399+ fastSchema. getSchemaAppliedDirectives(" link" ). collect { it. getArgument(" url" ). value } == [" https://a.dev" , " https://b.dev" ]
400+ fastSchema. getSchemaAppliedDirective(" owner" ). getArgument(" team" ). value == " graph"
401+ fastSchema. schemaDirectives. collect { it. name } == standardSchema. schemaDirectives. collect { it. name }
402+
403+ def options = SchemaPrinter.Options . defaultOptions(). includeSchemaDefinition(true )
404+ new SchemaPrinter (options). print (fastSchema) == new SchemaPrinter (options). print (standardSchema)
405+ }
406+
407+ def " schema extension definitions are captured like standard SchemaGenerator" () {
408+ given :
409+ def sdl = '''
410+ directive @owner(team: String!) on SCHEMA
411+
412+ schema { query: Query }
413+ extend schema @owner(team: "graph")
414+ extend schema { mutation: Mutation }
415+
416+ type Query { hello: String }
417+ type Mutation { bump: Int }
418+ '''
419+ def registry = new SchemaParser (). parse(sdl)
420+
421+ when :
422+ def standardSchema = new SchemaGenerator (). makeExecutableSchema(registry, RuntimeWiring . MOCKED_WIRING )
423+ def fastSchema = new FastSchemaGenerator (). makeExecutableSchema(registry, RuntimeWiring . MOCKED_WIRING )
424+
425+ then :
426+ fastSchema. mutationType. name == " Mutation"
427+ fastSchema. definition != null
428+ fastSchema. extensionDefinitions. size() == 2
429+ fastSchema. extensionDefinitions == standardSchema. extensionDefinitions
430+ }
431+
432+ def " schema AST definitions are not captured when captureAstDefinitions is false" () {
433+ given :
434+ def sdl = '''
435+ directive @owner(team: String!) on SCHEMA
436+
437+ schema { query: Query }
438+ extend schema @owner(team: "graph")
439+
440+ type Query { hello: String }
441+ '''
442+ def options = SchemaGenerator.Options . defaultOptions(). captureAstDefinitions(false )
443+
444+ when :
445+ def fastSchema = new FastSchemaGenerator (). makeExecutableSchema(options, new SchemaParser (). parse(sdl), RuntimeWiring . MOCKED_WIRING )
446+
447+ then :
448+ fastSchema. definition == null
449+ fastSchema. extensionDefinitions. isEmpty()
450+ fastSchema. getSchemaAppliedDirective(" owner" ) != null
451+ }
452+
373453}
0 commit comments