Exemple #1
0
        public UnionTypeDefinition UnionType(string name, TsDir directory = null, params TypedFile[] files)
        {
            var unionTypeDefinition = new UnionTypeDefinition(name, directory ?? RootDir);

            unionTypeDefinition.TypesForUnion.AddRange(files);

            UnionTypeDefinitions.Add(unionTypeDefinition);

            return(unionTypeDefinition);
        }
Exemple #2
0
 public IEnumerable <ITypeDeclaration> GetTypeDeclarations()
 {
     return(document.Children.Concat(options.ScalarTypes).Select(def => def switch
     {
         ObjectTypeDefinition objectTypeDefinition => new ObjectTypeContext(objectTypeDefinition, options, document) as ITypeDeclaration,
         InputObjectTypeDefinition inputObjectTypeDefinition => new InputObjectTypeContext(inputObjectTypeDefinition, options, document) as ITypeDeclaration,
         InterfaceTypeDefinition interfaceTypeDefinition => new InterfaceTypeContext(interfaceTypeDefinition, options, document) as ITypeDeclaration,
         EnumTypeDefinition enumTypeDefinition => new EnumTypeContext(enumTypeDefinition, options, document) as ITypeDeclaration,
         UnionTypeDefinition unionTypeDefinition => new UnionTypeContext(unionTypeDefinition, options) as ITypeDeclaration,
         ScalarTypeDefinition scalarTypeDefinition => new ScalarTypeContext(scalarTypeDefinition, options) as ITypeDeclaration,
         SchemaDefinition _ => null,
         _ => throw new InvalidOperationException("Unhandled definition type " + def.Kind.ToString("g"))
     })
Exemple #3
0
        public UnionTypeExtension Create(IDescriptorContext context, UnionTypeExtensionNode node)
        {
            var typeDefinition = new UnionTypeDefinition(node.Name.Value);

            typeDefinition.BindTo = node.GetBindingValue();

            foreach (NamedTypeNode namedType in node.Types)
            {
                typeDefinition.Types.Add(TypeReference.Create(namedType));
            }

            SdlToTypeSystemHelper.AddDirectives(typeDefinition, node);

            return(UnionTypeExtension.CreateUnsafe(typeDefinition));
        }
Exemple #4
0
        protected override void OnCompleteTypeSet(
            ITypeCompletionContext context,
            UnionTypeDefinition definition,
            ISet <ObjectType> typeSet)
        {
            base.OnCompleteTypeSet(context, definition, typeSet);

            Type markerType = definition.RuntimeType;

            if (markerType != typeof(object))
            {
                foreach (ObjectType type in context.GetTypes <ObjectType>())
                {
                    if (type.RuntimeType != typeof(object) &&
                        markerType.IsAssignableFrom(type.RuntimeType))
                    {
                        typeSet.Add(type);
                    }
                }
            }
        }
Exemple #5
0
        public UnionType Create(IDescriptorContext context, UnionTypeDefinitionNode node)
        {
            var preserveSyntaxNodes = context.Options.PreserveSyntaxNodes;

            var typeDefinition = new UnionTypeDefinition(
                node.Name.Value,
                node.Description?.Value);

            typeDefinition.BindTo = node.GetBindingValue();

            if (preserveSyntaxNodes)
            {
                typeDefinition.SyntaxNode = node;
            }

            foreach (NamedTypeNode namedType in node.Types)
            {
                typeDefinition.Types.Add(TypeReference.Create(namedType));
            }

            SdlToTypeSystemHelper.AddDirectives(typeDefinition, node);

            return(UnionType.CreateUnsafe(typeDefinition));
        }
Exemple #6
0
 public UnionTypeContext(UnionTypeDefinition unionTypeDefinition, GraphQLGenerationOptions options)
 {
     this.unionTypeDefinition = unionTypeDefinition;
     this.options             = options;
 }