printSchemaWithDirectives order as printSchema order #2752
-
Can we obtain the output of It's better to make an example. Here is a simple code snippet (using TypeGraphQL & Apollo federation for custom directives). Skip the boilerplate code. The executable schema is sorted using // Boilerplate
@ObjectType()
@Directive(`@key(fields: "id")`)
class Person {
@Field()
id!: number;
@Field()
name!: string;
}
@Resolver(() => Person)
class PersonResolver {
@Query(() => Person)
makePerson(@Arg('id') id: number, @Arg('name') name: string): Person {
return { id, name };
}
@Query({ deprecationReason: 'This field is deprecated' })
deprecatedField(): boolean {
return true;
}
}
const schema = buildFederatedSchema({ resolvers: [PersonResolver], orphanedTypes: [Person] });
// END Boilerplate
// Sort schema
const schemaSorted = lexicographicSortSchema(schema);
const schema_from_graphql = printSchema(schemaSorted);
const schema_from_graphql_tools = printSchemaWithDirectives(schemaSorted);
fs.writeFileSync('schema_from_graphql.graphql', schema_from_graphql);
fs.writeFileSync('schema_from_graphql_tools.graphql', schema_from_graphql_tools); schema_from_graphql.graphql directive @extends on INTERFACE | OBJECT
directive @external on FIELD_DEFINITION | OBJECT
directive @key(fields: String!) on INTERFACE | OBJECT
directive @provides(fields: String!) on FIELD_DEFINITION
directive @requires(fields: String!) on FIELD_DEFINITION
type Person {
id: Float!
name: String!
}
type Query {
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
deprecatedField: Boolean! @deprecated(reason: "This field is deprecated")
makePerson(id: Float!, name: String!): Person!
}
scalar _Any
union _Entity = Person
type _Service {
"""
The sdl representing the federated service capabilities. Includes federation directives, removes federation types, and includes rest of full schema after schema directives have been applied
"""
sdl: String
} schema_from_graphql_tools schema {
query: Query
}
type Person @key(fields: "id") {
id: Float!
name: String!
}
type Query {
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
deprecatedField: Boolean! @deprecated(reason: "This field is deprecated")
makePerson(id: Float!, name: String!): Person!
}
scalar _Any
union _Entity = Person
type _Service {
"""The sdl representing the federated service capabilities. Includes federation directives, removes federation types, and includes rest of full schema after schema directives have been applied"""
sdl: String
}
directive @extends on INTERFACE | OBJECT
directive @external on FIELD_DEFINITION | OBJECT
directive @key(fields: String!) on INTERFACE | OBJECT
directive @provides(fields: String!) on FIELD_DEFINITION
directive @requires(fields: String!) on FIELD_DEFINITION As we can see the Can we obtain the same "order" as the one from 'graphql-js'? Thanks in advance🎉 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Will be available in a few minutes |
Beta Was this translation helpful? Give feedback.
Will be available in a few minutes
d2a17c7