sangria
sangria copied to clipboard
AstSchemaMaterializer: Type used in directives is not detected as an additional type
I wanted to construct a schema from the AST:
val schema = Schema.buildFromAst(graphql"""
schema {
query: Query
}
type Query {
field: Int
_service: _Service!
}
scalar _FieldSet
scalar _Any
type _Service {
sdl: String
}
directive @extends on INTERFACE | OBJECT
directive @external on FIELD_DEFINITION
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
directive @key(fields: _FieldSet!) on OBJECT | INTERFACE
""")
but the schema builder fails to detect the _FieldSet scalar, although _Any is detected 🤷♂️. The output of the render is:
type Query {
field: Int
_service: _Service!
}
scalar _Any
type _Service {
sdl: String
}
directive @extends on INTERFACE | OBJECT
directive @external on FIELD_DEFINITION
directive @key(fields: _FieldSet!) on INTERFACE | OBJECT
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
I think this is related to the findUnusedTypes in the builder:
builder.buildSchema(
schemaInfo.definition,
schemaExtensionDefs.toList,
queryType,
mutationType,
subscriptionType,
findUnusedTypes()._2.toList,
BuiltinDirectives ++ directives,
this
)
The findUnusedTypes function fails to detect the additionalType because it's used in the directives (compared to the unused _Any).