New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SchemaExporter, schema.ToAST(), and schema.Print() #3649
Conversation
if (graphType.HasExtensionAstTypes() && graphType.GetAstType<ASTNode>() == null) | ||
{ | ||
return node switch | ||
{ | ||
GraphQLObjectTypeDefinition otd => new GraphQLObjectTypeExtension(otd.Name) | ||
{ | ||
Interfaces = otd.Interfaces, | ||
Fields = otd.Fields, | ||
Directives = otd.Directives, | ||
Comments = otd.Comments, | ||
}, | ||
GraphQLInterfaceTypeDefinition itd => new GraphQLInterfaceTypeExtension(itd.Name) | ||
{ | ||
Interfaces = itd.Interfaces, | ||
Fields = itd.Fields, | ||
Directives = itd.Directives, | ||
Comments = itd.Comments, | ||
}, | ||
GraphQLUnionTypeDefinition utd => new GraphQLUnionTypeExtension(utd.Name) | ||
{ | ||
Types = utd.Types, | ||
Directives = utd.Directives, | ||
Comments = utd.Comments, | ||
}, | ||
GraphQLScalarTypeDefinition std => new GraphQLScalarTypeExtension(std.Name) | ||
{ | ||
Directives = std.Directives, | ||
Comments = std.Comments, | ||
}, | ||
GraphQLEnumTypeDefinition etd => new GraphQLEnumTypeExtension(etd.Name) | ||
{ | ||
Values = etd.Values, | ||
Directives = etd.Directives, | ||
Comments = etd.Comments, | ||
}, | ||
GraphQLInputObjectTypeDefinition iotd => new GraphQLInputObjectTypeExtension(iotd.Name) | ||
{ | ||
Fields = iotd.Fields, | ||
Directives = iotd.Directives, | ||
Comments = iotd.Comments, | ||
}, | ||
GraphQLSchemaDefinition sd => new GraphQLSchemaExtension | ||
{ | ||
OperationTypes = sd.OperationTypes, | ||
Directives = sd.Directives, | ||
Comments = sd.Comments, | ||
}, | ||
_ => throw new InvalidOperationException($"Invalid node type of '{node.GetType().GetFriendlyName()}'.") | ||
}; | ||
} | ||
else | ||
{ | ||
return node; | ||
} |
Check notice
Code scanning / CodeQL
Missed ternary opportunity Note
if (directive.Name.Value == "deprecated") | ||
{ | ||
if (directive.Arguments != null) | ||
{ | ||
directive.Arguments.Items.RemoveAll(a => a.Name.Value == "reason"); | ||
if (directive.Arguments.Items.Count == 0) | ||
{ | ||
directive.Arguments = null; | ||
} | ||
} | ||
} |
Check notice
Code scanning / CodeQL
Nested 'if' statements can be combined Note
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## master #3649 +/- ##
==========================================
+ Coverage 84.01% 84.03% +0.02%
==========================================
Files 394 399 +5
Lines 17099 17593 +494
Branches 2736 2799 +63
==========================================
+ Hits 14366 14785 +419
- Misses 2084 2145 +61
- Partials 649 663 +14
|
This PR adds capability to 'export' a configured GraphQL.NET schema into an AST document suitable for printing by GraphQL.NET Parser into SDL. The new
SchemaExporter
class currently has no options and will export the entire schema. The GraphQL.NET Parser library will then handle sorting the schema and/or printing it, as desired. An extension method has been added toISchema
to easily export and print the schema in one step. In order to support theIncludeDeprecationReasons
andIncludeDescriptions
properties of the oldSchemaPrinter
, AST visitors have been added to remove the undesired information.Those properties have a default value of
true
(previouslyfalse
). The property for sorting preferences defaults to unsorted. All in, this should remove the need for theSchemaPrinter
andFederatedSchemaPrinter
classes.Waiting on:
Replaces:
Closes: