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); }
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")) })
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)); }
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); } } } }
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)); }
public UnionTypeContext(UnionTypeDefinition unionTypeDefinition, GraphQLGenerationOptions options) { this.unionTypeDefinition = unionTypeDefinition; this.options = options; }