Skip to content

Commit

Permalink
feat(schema): allow a way to extend another type
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhck committed Jun 5, 2021
1 parent 198dbe7 commit d2d4f2b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Micro.GraphQL.Federation/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public static void BuildAstMeta(this IProvideMetadata type, string name, string
//type.SetAstType(definition);
type.Metadata["__AST_MetaField__"] = definition;
}
public static void BuildExtensionAstMeta(this IProvideMetadata type, string name, string value = null)
{
var definition = BuildGraphQLObjectTypeDefinition();
var directive = BuildGraphQLDirective(name, value, ASTNodeKind.Argument);
AddDirective(definition, directive);
// type.AddExtensionAstType(definition);
type.Metadata["__EXTENSION_AST_MetaField__"] = new List<ASTNode> {definition};
}
private static void AddDirective(GraphQLObjectTypeDefinition definition, GraphQLDirective directive) => ((List<GraphQLDirective>)definition.Directives).Add(directive);
private static GraphQLObjectTypeDefinition BuildGraphQLObjectTypeDefinition() => new GraphQLObjectTypeDefinition
{
Expand Down
11 changes: 11 additions & 0 deletions Micro.GraphQL.Federation/ObjectGraphType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ protected void Key(string fields)
this.BuildAstMeta("key", fields);
}

protected void Extend()
{
this.BuildExtensionAstMeta("extends");
}

protected void ExtendByKeys(string fields)
{
Key(fields);
Extend();
}

private void ResolveReferenceAsync(IFederatedResolver resolver)
{
// Metadata[FederatedSchemaBuilder.RESOLVER_METADATA_FIELD] = resolver;
Expand Down

0 comments on commit d2d4f2b

Please sign in to comment.