private static bool CanBeMerged(DirectiveDefinitionNode left, DirectiveDefinitionNode right) { if (!left.Name.Value.Equals(right.Name.Value, StringComparison.Ordinal)) { return(false); } if (left.Locations.Count != right.Locations.Count) { return(false); } var leftLocations = left.Locations.Select(l => l.Value).OrderBy(l => l).ToList(); var rightLocations = right.Locations.Select(l => l.Value).OrderBy(l => l).ToList(); if (!leftLocations.SequenceEqual(rightLocations)) { return(false); } if (left.IsRepeatable != right.IsRepeatable) { return(false); } if (left.Arguments.Count != right.Arguments.Count) { return(false); } return(ComplexTypeMergeHelpers.HasSameArguments(left.Arguments, right.Arguments)); }
public static DocumentNode Deserialize(string json) { if (string.IsNullOrEmpty(json)) { throw new ArgumentException(StitchingResources .IntrospectionDeserializer_Json_NullOrEmpty, nameof(json)); } IntrospectionResult result = JsonConvert .DeserializeObject <IntrospectionResult>(json); var typeDefinitions = new List <IDefinitionNode>(); typeDefinitions.Add(CreateSchema(result.Data.Schema)); typeDefinitions.AddRange(CreateTypes(result.Data.Schema.Types)); foreach (Directive directive in result.Data.Schema.Directives) { DirectiveDefinitionNode directiveDefinition = CreateDirectiveDefinition(directive); if (directiveDefinition.Locations.Any()) { typeDefinitions.Add(directiveDefinition); } } return(new DocumentNode(typeDefinitions)); }
public DirectiveTypeInfo( DirectiveDefinitionNode definition, ISchemaInfo schema) { Definition = definition; Schema = schema; }
protected override void VisitDirectiveDefinition( DirectiveDefinitionNode node, object context) { _types.Add(SchemaTypeReference.Create( _directiveTypeFactory.Create(_bindingLookup, node))); }
public static DirectiveDefinitionNode Rename( this DirectiveDefinitionNode directiveDefinition, NameString newName, IEnumerable <NameString> schemaNames) { return(directiveDefinition.WithName(new NameNode(newName))); }
protected override void VisitDirectiveDefinition( DirectiveDefinitionNode node, object context) { _directiveRegistry.RegisterDirectiveType( _directiveTypeFactory.Create(node)); }
protected override void VisitDirectiveDefinition( DirectiveDefinitionNode node, TypeDefinitionItem context) { VisitName(node.Name, context); VisitIfNotNull(node.Description, context, VisitStringValue); VisitMany(node.Arguments, context, VisitInputValueDefinition); VisitMany(node.Locations, context, VisitName); }
public static DirectiveDefinitionNode Rename( this DirectiveDefinitionNode directiveDefinition, NameString newName, params NameString[] schemaNames) { return(Rename( directiveDefinition, newName, (IEnumerable <NameString>)schemaNames)); }
public void AddDirective(DirectiveDefinitionNode directive) { if (directive == null) { throw new ArgumentNullException(nameof(directive)); } if (_dirs.ContainsKey(directive.Name.Value)) { throw new ArgumentException( "A type with that name was already added."); } _dirs.Add(directive.Name.Value, directive); }
protected void MergeTypes( ISchemaMergeContext context, IReadOnlyList <IDirectiveTypeInfo> types, NameString newTypeName) { var definitions = types .Select(t => t.Definition) .ToList(); DirectiveDefinitionNode definition = definitions[0].Rename( newTypeName, types.Select(t => t.Schema.Name)); context.AddDirective(definition); }
protected sealed override ISyntaxVisitorAction Enter( ISyntaxNode node, ISyntaxVisitorContext context) { return(node switch { DocumentNode n => Enter(n, context), OperationDefinitionNode n => Enter(n, context), VariableDefinitionNode n => Enter(n, context), VariableNode n => Enter(n, context), SelectionSetNode n => Enter(n, context), FieldNode n => Enter(n, context), ArgumentNode n => Enter(n, context), FragmentSpreadNode n => Enter(n, context), InlineFragmentNode n => Enter(n, context), FragmentDefinitionNode n => Enter(n, context), DirectiveNode n => Enter(n, context), NamedTypeNode n => Enter(n, context), ListTypeNode n => Enter(n, context), NonNullTypeNode n => Enter(n, context), ListValueNode n => Enter(n, context), ObjectValueNode n => Enter(n, context), ObjectFieldNode n => Enter(n, context), IValueNode n => Enter(n, context), SchemaDefinitionNode n => Enter(n, context), OperationTypeDefinitionNode n => Enter(n, context), ScalarTypeDefinitionNode n => Enter(n, context), ObjectTypeDefinitionNode n => Enter(n, context), FieldDefinitionNode n => Enter(n, context), InputValueDefinitionNode n => Enter(n, context), InterfaceTypeDefinitionNode n => Enter(n, context), UnionTypeDefinitionNode n => Enter(n, context), EnumTypeDefinitionNode n => Enter(n, context), EnumValueDefinitionNode n => Enter(n, context), InputObjectTypeDefinitionNode n => Enter(n, context), DirectiveDefinitionNode n => Enter(n, context), SchemaExtensionNode n => Enter(n, context), ScalarTypeExtensionNode n => Enter(n, context), ObjectTypeExtensionNode n => Enter(n, context), InterfaceTypeExtensionNode n => Enter(n, context), UnionTypeExtensionNode n => Enter(n, context), EnumTypeExtensionNode n => Enter(n, context), InputObjectTypeExtensionNode n => Enter(n, context), _ => throw new NotSupportedException() });
public static DocumentNode Deserialize(IntrospectionResult result) { var typeDefinitions = new List <IDefinitionNode>(); typeDefinitions.Add(CreateSchema(result.Data.Schema)); typeDefinitions.AddRange(CreateTypes(result.Data.Schema.Types)); foreach (Directive directive in result.Data.Schema.Directives) { DirectiveDefinitionNode directiveDefinition = CreateDirectiveDefinition(directive); if (directiveDefinition.Locations.Any()) { typeDefinitions.Add(directiveDefinition); } } return(new DocumentNode(typeDefinitions)); }
private void VisitDirectiveDefinition( DirectiveDefinitionNode node, ISyntaxWriter writer) { WriteDescription(node.Description, writer); writer.Write(Keywords.Directive); writer.WriteSpace(); writer.Write('@'); writer.WriteName(node.Name); if (node.Arguments.Count > 0) { writer.Write("("); writer.WriteMany( node.Arguments, VisitArgumentValueDefinition, w => w.WriteSpace()); writer.Write(")"); } writer.WriteSpace(); if (node.IsRepeatable) { writer.Write(Keywords.Repeatable); writer.WriteSpace(); } writer.Write(Keywords.On); writer.WriteSpace(); writer.WriteMany(node.Locations, (n, w) => writer.WriteName(n), " | "); }
protected virtual ISyntaxVisitorAction Enter( DirectiveDefinitionNode node, ISyntaxVisitorContext context) => DefaultAction;
public new IDirectiveTypeDescriptor <T> SyntaxNode( DirectiveDefinitionNode directiveDefinitionNode) { base.SyntaxNode(directiveDefinitionNode); return(this); }
protected void SyntaxNode(DirectiveDefinitionNode syntaxNode) { DirectiveDescription.SyntaxNode = syntaxNode; }
IDirectiveTypeDescriptor IDirectiveTypeDescriptor.SyntaxNode( DirectiveDefinitionNode syntaxNode) { SyntaxNode(syntaxNode); return(this); }
protected virtual ISyntaxVisitorAction Leave( DirectiveDefinitionNode node, TContext context) => DefaultAction;
public IDirectiveTypeDescriptor SyntaxNode( DirectiveDefinitionNode directiveDefinitionNode) { Definition.SyntaxNode = directiveDefinitionNode; return(this); }
protected virtual void VisitDirectiveDefinition(DirectiveDefinitionNode node) { }