protected virtual InterfaceGraphType ToInterfaceType(GraphQLInterfaceTypeDefinition interfaceDef) { var name = (string)interfaceDef.Name.Value; var typeConfig = Types.For(name); AssertKnownType(typeConfig); var type = new InterfaceGraphType { Name = name, Description = typeConfig.Description ?? interfaceDef.Description?.Value.ToString() ?? interfaceDef.Comment?.Text.ToString(), ResolveType = typeConfig.ResolveType, }.SetAstType(interfaceDef); OverrideDeprecationReason(type, typeConfig.DeprecationReason); typeConfig.CopyMetadataTo(type); if (interfaceDef.Fields != null) { foreach (var f in interfaceDef.Fields) { type.AddField(ToFieldType(type.Name, f)); } } return(type); }
public FieldType AddNavigationField <TSource, TReturn>( InterfaceGraphType <TSource> graph, string name, Type?graphType = null, IEnumerable <string>?includeNames = null) where TReturn : class { Guard.AgainstNull(nameof(graph), graph); var field = BuildNavigationField <TSource, TReturn>(name, null, includeNames, graphType); return(graph.AddField(field)); }
public FieldType AddQueryField <TSource, TReturn>( InterfaceGraphType <TSource> graph, string name, Type?itemGraphType = null, IEnumerable <QueryArgument>?arguments = null) where TReturn : class { Guard.AgainstNull(nameof(graph), graph); var field = BuildQueryField <TSource, TReturn>(name, null, arguments, itemGraphType); return(graph.AddField(field)); }
public FieldType AddNavigationListField <TSource, TReturn>( InterfaceGraphType <TSource> graph, string name, Type?itemGraphType = null, IEnumerable <QueryArgument>?arguments = null, IEnumerable <string>?includeNames = null, string?description = null) where TReturn : class { Guard.AgainstNull(nameof(graph), graph); var field = BuildNavigationField <TSource, TReturn>(itemGraphType, name, null, includeNames, arguments, description); return(graph.AddField(field)); }
public void AddQueryConnectionField <TSource, TReturn>( InterfaceGraphType <TSource> graph, string name, Type?itemGraphType = null, IEnumerable <QueryArgument>?arguments = null, int pageSize = 10) where TReturn : class { Guard.AgainstNull(nameof(graph), graph); var connection = BuildQueryConnectionField <TSource, TReturn>(name, null, pageSize, itemGraphType); var field = graph.AddField(connection.FieldType); field.AddWhereArgument(arguments); }
public EmptyInterfaceSchema() { Query = new ObjectGraphType { Name = "Query" }; Query.AddField(new FieldType { Name = "field", ResolvedType = new StringGraphType() }); var iface = new InterfaceGraphType { Name = "Empty", ResolveType = _ => null }; RegisterType(iface); Query.ResolvedInterfaces.Add(iface); }
public static void Build(InterfaceGraphType graphType, Type type) { if (!type.IsInterface && !type.IsAbstract) { throw new InvalidOperationException("type must be an abstract type or an interface"); } ProcessInterfaceType(graphType, type); bool hasDataContract = type.ShouldIncludeInGraph(); // KnownTypeAttribute could be used when SchemaType and DomainType are the same ProcessType(graphType, type); ProcessProperties(graphType, GetProperties(hasDataContract, type)); ProcessFields(graphType, GetFields(hasDataContract, type)); ProcessMethods(graphType, type, type.GetMethods()); }
protected virtual InterfaceGraphType ToInterfaceType(GraphQLInterfaceTypeDefinition interfaceDef) { var typeConfig = Types.For(interfaceDef.Name.Value); var type = new InterfaceGraphType(); type.Name = interfaceDef.Name.Value; type.Description = typeConfig.Description; type.ResolveType = typeConfig.ResolveType; CopyMetadata(type, typeConfig); var fields = interfaceDef.Fields.Select(f => ToFieldType(type.Name, f)); fields.Apply(f => type.AddField(f)); return(type); }
public void AddNavigationConnectionField <TSource, TReturn>( InterfaceGraphType <TSource> graph, string name, Type?itemGraphType = null, IEnumerable <QueryArgument>?arguments = null, IEnumerable <string>?includeNames = null, int pageSize = 10, string?description = null) where TReturn : class { Guard.AgainstNull(nameof(graph), graph); var connection = BuildListConnectionField <TSource, TReturn>(name, null, includeNames, pageSize, itemGraphType, description); var field = graph.AddField(connection.FieldType); field.AddWhereArgument(arguments); }
/// <summary> /// Inspects the given type and, in accordance with the rules of this maker, will /// generate a complete set of necessary graph types required to support it. /// </summary> /// <param name="concreteType">The concrete type to incorporate into the schema.</param> /// <returns>GraphTypeCreationResult.</returns> public GraphTypeCreationResult CreateGraphType(Type concreteType) { if (concreteType == null) { return(null); } var template = GraphQLProviders.TemplateProvider.ParseType(concreteType, TypeKind.INTERFACE) as IInterfaceGraphTypeTemplate; if (template == null) { return(null); } var result = new GraphTypeCreationResult(); var formatter = _schema.Configuration.DeclarationOptions.GraphNamingFormatter; var fieldSet = new List <IGraphField>(); var fieldMaker = GraphQLProviders.GraphTypeMakerProvider.CreateFieldMaker(_schema); foreach (var fieldTemplate in ObjectGraphTypeMaker.GatherFieldTemplates(template, _schema)) { var fieldResult = fieldMaker.CreateField(fieldTemplate); fieldSet.Add(fieldResult.Field); result.MergeDependents(fieldResult); } var interfaceType = new InterfaceGraphType( formatter.FormatGraphTypeName(template.Name), template.ObjectType, fieldSet) { Description = template.Description, Publish = template.Publish, }; result.GraphType = interfaceType; result.ConcreteType = concreteType; return(result); }
protected virtual InterfaceGraphType ToInterfaceType(GraphQLInterfaceTypeDefinition interfaceDef) { var typeConfig = Types.For(interfaceDef.Name.Value); var type = new InterfaceGraphType { Name = interfaceDef.Name.Value, Description = typeConfig.Description ?? interfaceDef.Comment?.Text, ResolveType = typeConfig.ResolveType }; ApplyDeprecatedDirective(interfaceDef.Directives, reason => type.DeprecationReason = typeConfig.DeprecationReason ?? reason); CopyMetadata(type, typeConfig); var fields = interfaceDef.Fields.Select(f => ToFieldType(type.Name, f)); fields.Apply(f => type.AddField(f)); return(type); }
protected virtual InterfaceGraphType ToInterfaceType(GraphQLInterfaceTypeDefinition interfaceDef) { var typeConfig = Types.For(interfaceDef.Name.Value); var type = new InterfaceGraphType { Name = interfaceDef.Name.Value, Description = typeConfig.Description ?? interfaceDef.Comment?.Text, ResolveType = typeConfig.ResolveType }.SetAstType(interfaceDef); VisitNode(type, v => v.VisitInterface(type)); CopyMetadata(type, typeConfig); var fields = interfaceDef.Fields.Select(f => ToFieldType(type.Name, f)); fields.Apply(f => type.AddField(f)); return(type); }
public SchemaWithDuplicateInterfaceFields() { Query = new ObjectGraphType { Name = "Query" }; var iface = new InterfaceGraphType { Name = "Dup", ResolveType = _ => null }; iface.AddField(new FieldType { Name = "field", ResolvedType = new StringGraphType() }); iface.AddField(new FieldType { Name = "field_2", ResolvedType = new StringGraphType() }); // bypass HasField check iface.Fields.List[1].Name = "field"; Query.AddField(new FieldType { Name = "field", ResolvedType = new StringGraphType() }); RegisterType(iface); Query.ResolvedInterfaces.Add(iface); }
private static void ProcessInterfaceType(InterfaceGraphType interfaceGraphType, Type type) { interfaceGraphType.ResolveType = CreateResolveType(type); }
public static IEnumerable <IGraphType> CreateGraphTypes( IEnumerable <IContentTypeComposition> contentTypes, PublishedItemType publishedItemType, Func <IContentTypeBase, string> resolveName = null) { if (resolveName == null) { resolveName = Conventions.NameResolvers.PascalCase; } var interfaceGraphTypes = new Dictionary <string, IInterfaceGraphType>(); //TODO: Whitelist/blacklist content types var contentTypeList = contentTypes.ToList(); var compositions = contentTypeList.SelectMany(x => x.ContentTypeComposition).Distinct().ToList(); foreach (var contentType in compositions) { var graphType = new InterfaceGraphType <IPublishedContent> { Name = resolveName(contentType), Description = contentType.Description, Metadata = { ["documentTypeAlias"] = contentType.Alias, } }; graphType.AddUmbracoContentPropeties(contentType, publishedItemType); yield return(graphType); interfaceGraphTypes.Add(contentType.Alias, graphType); } foreach (var contentType in contentTypeList.Except(compositions)) { var graphType = new ObjectGraphType <IPublishedContent> { Name = resolveName(contentType), Description = contentType.Description, IsTypeOf = content => ((IPublishedContent)content).DocumentTypeAlias == contentType.Alias, Metadata = { ["documentTypeAlias"] = contentType.Alias, ["allowedAtRoot"] = contentType.AllowedAsRoot, ["allowedChildren"] = contentType.AllowedContentTypes.Select(x => x.Alias).ToArray(), } }; graphType.Interface <PublishedContentGraphType>(); foreach (var composition in contentType.ContentTypeComposition) { if (interfaceGraphTypes.TryGetValue(composition.Alias, out IInterfaceGraphType interfaceType)) { graphType.AddResolvedInterface(interfaceType); } } graphType.AddUmbracoBuiltInProperties(); graphType.AddUmbracoContentPropeties(contentType, publishedItemType); yield return(graphType); } }
public virtual void VisitInterface(InterfaceGraphType iface) { }
public void can_create_custom_directive_for_all_locations_graph_type_first() { var schema = new Schema(); schema.ApplyDirective("schema"); schema.HasAppliedDirectives().ShouldBeTrue(); schema.GetAppliedDirectives().Count.ShouldBe(1); var objectType = new ObjectGraphType(); objectType.ApplyDirective("type"); objectType.HasAppliedDirectives().ShouldBeTrue(); objectType.GetAppliedDirectives().Count.ShouldBe(1); var field = objectType.Field <StringGraphType>("test"); field.ApplyDirective("field"); field.HasAppliedDirectives().ShouldBeTrue(); field.GetAppliedDirectives().Count.ShouldBe(1); var interfaceType = new InterfaceGraphType(); interfaceType.ApplyDirective("interface"); interfaceType.HasAppliedDirectives().ShouldBeTrue(); interfaceType.GetAppliedDirectives().Count.ShouldBe(1); var unionType = new UnionGraphType(); unionType.ApplyDirective("union"); unionType.HasAppliedDirectives().ShouldBeTrue(); unionType.GetAppliedDirectives().Count.ShouldBe(1); var arg = new QueryArgument(new StringGraphType()); arg.ApplyDirective("arg"); arg.HasAppliedDirectives().ShouldBeTrue(); arg.GetAppliedDirectives().Count.ShouldBe(1); var enumType = new EnumerationGraphType(); enumType.ApplyDirective("enumType"); enumType.HasAppliedDirectives().ShouldBeTrue(); enumType.GetAppliedDirectives().Count.ShouldBe(1); var enumValue = new EnumValueDefinition("UNUSED", null); enumValue.ApplyDirective("enumValue"); enumValue.HasAppliedDirectives().ShouldBeTrue(); enumValue.GetAppliedDirectives().Count.ShouldBe(1); var inputType = new InputObjectGraphType(); inputType.ApplyDirective("inputType"); inputType.HasAppliedDirectives().ShouldBeTrue(); inputType.GetAppliedDirectives().Count.ShouldBe(1); var input = inputType.Field <StringGraphType>("test"); input.ApplyDirective("inputField"); input.HasAppliedDirectives().ShouldBeTrue(); input.GetAppliedDirectives().Count.ShouldBe(1); var scalarType = new BigIntGraphType(); scalarType.ApplyDirective("scalar"); scalarType.HasAppliedDirectives().ShouldBeTrue(); scalarType.GetAppliedDirectives().Count.ShouldBe(1); }
public InterfacesType(InterfaceGraphType oldType, InterfaceGraphType newType) { this.oldType = oldType; this.newType = newType; }
public string PrintInterface(InterfaceGraphType type) { return("interface {1} {{{0}{2}{0}}}".ToFormat(Environment.NewLine, type.Name, PrintFields(type))); }