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));
        }
예제 #3
0
 public DirectiveTypeInfo(
     DirectiveDefinitionNode definition,
     ISchemaInfo schema)
 {
     Definition = definition;
     Schema     = schema;
 }
예제 #4
0
 protected override void VisitDirectiveDefinition(
     DirectiveDefinitionNode node,
     object context)
 {
     _types.Add(SchemaTypeReference.Create(
                    _directiveTypeFactory.Create(_bindingLookup, node)));
 }
예제 #5
0
 public static DirectiveDefinitionNode Rename(
     this DirectiveDefinitionNode directiveDefinition,
     NameString newName,
     IEnumerable <NameString> schemaNames)
 {
     return(directiveDefinition.WithName(new NameNode(newName)));
 }
예제 #6
0
 protected override void VisitDirectiveDefinition(
     DirectiveDefinitionNode node,
     object context)
 {
     _directiveRegistry.RegisterDirectiveType(
         _directiveTypeFactory.Create(node));
 }
예제 #7
0
 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);
 }
예제 #8
0
 public static DirectiveDefinitionNode Rename(
     this DirectiveDefinitionNode directiveDefinition,
     NameString newName,
     params NameString[] schemaNames)
 {
     return(Rename(
                directiveDefinition,
                newName,
                (IEnumerable <NameString>)schemaNames));
 }
예제 #9
0
        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);
        }
예제 #11
0
 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));
        }
예제 #13
0
        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),
                             " | ");
        }
예제 #14
0
 protected virtual ISyntaxVisitorAction Enter(
     DirectiveDefinitionNode node,
     ISyntaxVisitorContext context) =>
 DefaultAction;
 public new IDirectiveTypeDescriptor <T> SyntaxNode(
     DirectiveDefinitionNode directiveDefinitionNode)
 {
     base.SyntaxNode(directiveDefinitionNode);
     return(this);
 }
예제 #16
0
 protected void SyntaxNode(DirectiveDefinitionNode syntaxNode)
 {
     DirectiveDescription.SyntaxNode = syntaxNode;
 }
예제 #17
0
 IDirectiveTypeDescriptor IDirectiveTypeDescriptor.SyntaxNode(
     DirectiveDefinitionNode syntaxNode)
 {
     SyntaxNode(syntaxNode);
     return(this);
 }
 protected virtual ISyntaxVisitorAction Leave(
     DirectiveDefinitionNode node,
     TContext context) =>
 DefaultAction;
예제 #19
0
 public IDirectiveTypeDescriptor SyntaxNode(
     DirectiveDefinitionNode directiveDefinitionNode)
 {
     Definition.SyntaxNode = directiveDefinitionNode;
     return(this);
 }
예제 #20
0
 protected virtual void VisitDirectiveDefinition(DirectiveDefinitionNode node)
 {
 }