Beispiel #1
0
        public ContentDataGraphInputType(IGraphModel model, ISchemaEntity schema)
        {
            var schemaType = schema.TypeName();
            var schemaName = schema.DisplayName();

            Name = $"{schemaType}InputDto";

            foreach (var field in schema.SchemaDef.Fields.Where(x => !x.IsHidden))
            {
                var inputType = model.GetInputGraphType(field);

                if (inputType != null)
                {
                    if (field.RawProperties.IsRequired)
                    {
                        inputType = new NonNullGraphType(inputType);
                    }

                    var fieldName = field.RawProperties.Label.WithFallback(field.Name);

                    var fieldGraphType = new InputObjectGraphType
                    {
                        Name = $"{schemaType}Data{field.Name.ToPascalCase()}InputDto"
                    };

                    var partition = model.ResolvePartition(field.Partitioning);

                    foreach (var partitionItem in partition)
                    {
                        fieldGraphType.AddField(new FieldType
                        {
                            Name         = partitionItem.Key,
                            ResolvedType = inputType,
                            Resolver     = null,
                            Description  = field.RawProperties.Hints
                        });
                    }

                    fieldGraphType.Description = $"The input structure of the {fieldName} of a {schemaName} content type.";

                    var fieldResolver = new FuncFieldResolver <NamedContentData, ContentFieldData>(c => c.Source.GetOrDefault(field.Name));

                    AddField(new FieldType
                    {
                        Name         = field.Name.ToCamelCase(),
                        Resolver     = fieldResolver,
                        ResolvedType = fieldGraphType,
                        Description  = $"The {fieldName} field."
                    });
                }
            }

            Description = $"The structure of a {schemaName} content type.";
        }
Beispiel #2
0
        public void Initialize(IGraphModel model, ISchemaEntity schema)
        {
            var schemaType = schema.TypeName();
            var schemaName = schema.DisplayName();

            Name = $"{schemaType}DataDto";

            foreach (var(field, fieldName, typeName) in schema.SchemaDef.Fields.SafeFields())
            {
                var(resolvedType, valueResolver) = model.GetGraphType(schema, field);

                if (valueResolver != null)
                {
                    var displayName = field.DisplayName();

                    var fieldGraphType = new ObjectGraphType
                    {
                        Name = $"{schemaType}Data{typeName}Dto"
                    };

                    var partition = model.ResolvePartition(field.Partitioning);

                    foreach (var partitionItem in partition)
                    {
                        var key = partitionItem.Key;

                        fieldGraphType.AddField(new FieldType
                        {
                            Name         = key.EscapePartition(),
                            Resolver     = PartitionResolver(valueResolver, key),
                            ResolvedType = resolvedType,
                            Description  = field.RawProperties.Hints
                        });
                    }

                    fieldGraphType.Description = $"The structure of the {displayName} field of the {schemaName} content type.";

                    AddField(new FieldType
                    {
                        Name         = fieldName,
                        Resolver     = FieldResolver(field),
                        ResolvedType = fieldGraphType,
                        Description  = $"The {displayName} field."
                    });
                }
            }

            Description = $"The structure of the {schemaName} content type.";
        }
Beispiel #3
0
        public ContentDataGraphType(ISchemaEntity schema, string schemaName, string schemaType, IGraphModel model)
        {
            Name = $"{schemaType}DataDto";

            foreach (var(field, fieldName, typeName) in schema.SchemaDef.Fields.SafeFields())
            {
                var(resolvedType, valueResolver, args) = model.GetGraphType(schema, field, typeName);

                if (valueResolver != null)
                {
                    var displayName = field.DisplayName();

                    var fieldGraphType = new ObjectGraphType
                    {
                        Name = $"{schemaType}Data{typeName}Dto"
                    };

                    var partitioning = model.ResolvePartition(field.Partitioning);

                    foreach (var partitionKey in partitioning.AllKeys)
                    {
                        fieldGraphType.AddField(new FieldType
                        {
                            Name         = partitionKey.EscapePartition(),
                            Arguments    = args,
                            Resolver     = ContentResolvers.Partition(valueResolver, partitionKey),
                            ResolvedType = resolvedType,
                            Description  = field.RawProperties.Hints
                        });
                    }

                    fieldGraphType.Description = $"The structure of the {displayName} field of the {schemaName} content type.";

                    AddField(new FieldType
                    {
                        Name         = fieldName,
                        Resolver     = ContentResolvers.Field(field),
                        ResolvedType = fieldGraphType,
                        Description  = $"The {displayName} field."
                    });
                }
            }

            Description = $"The structure of the {schemaName} data type.";
        }
Beispiel #4
0
        public ContentDataInputGraphType(ISchemaEntity schema, string schemaName, string schemaType, IGraphModel model)
        {
            Name = $"{schemaType}DataInputDto";

            foreach (var(field, fieldName, typeName) in schema.SchemaDef.Fields.SafeFields().Where(x => x.Field.IsForApi(true)))
            {
                var resolvedType = model.GetInputGraphType(schema, field, typeName);

                if (resolvedType != null)
                {
                    var displayName = field.DisplayName();

                    var fieldGraphType = new InputObjectGraphType
                    {
                        Name = $"{schemaType}Data{typeName}InputDto"
                    };

                    var partitioning = model.ResolvePartition(field.Partitioning);

                    foreach (var partitionKey in partitioning.AllKeys)
                    {
                        fieldGraphType.AddField(new FieldType
                        {
                            Name         = partitionKey.EscapePartition(),
                            ResolvedType = resolvedType,
                            Resolver     = null,
                            Description  = field.RawProperties.Hints
                        }).WithSourceName(partitionKey);
                    }

                    fieldGraphType.Description = $"The structure of the {displayName} field of the {schemaName} content input type.";

                    AddField(new FieldType
                    {
                        Name         = fieldName,
                        ResolvedType = fieldGraphType,
                        Resolver     = null,
                        Description  = $"The {displayName} field."
                    }).WithSourceName(field.Name);
                }
            }

            Description = $"The structure of the {schemaName} data input type.";
        }
        public void Initialize(IGraphModel model, ISchemaEntity schema)
        {
            var schemaType = schema.TypeName();
            var schemaName = schema.DisplayName();

            Name = $"{schemaType}DataDto";

            foreach (var field in schema.SchemaDef.Fields.ForApi())
            {
                var(resolvedType, valueResolver) = model.GetGraphType(schema, field);

                if (valueResolver != null)
                {
                    var fieldType = field.TypeName();
                    var fieldName = field.DisplayName();

                    var fieldGraphType = new ObjectGraphType
                    {
                        Name = $"{schemaType}Data{fieldType}Dto"
                    };

                    var partition = model.ResolvePartition(field.Partitioning);

                    foreach (var partitionItem in partition)
                    {
                        var key = partitionItem.Key;

                        var partitionResolver = new FuncFieldResolver <object>(c =>
                        {
                            if (((ContentFieldData)c.Source).TryGetValue(key, out var value))
                            {
                                return(valueResolver(value, c));
                            }
                            else
                            {
                                return(null);
                            }
                        });

                        fieldGraphType.AddField(new FieldType
                        {
                            Name         = key.EscapePartition(),
                            Resolver     = partitionResolver,
                            ResolvedType = resolvedType,
                            Description  = field.RawProperties.Hints
                        });
                    }

                    fieldGraphType.Description = $"The structure of the {fieldName} field of the {schemaName} content type.";

                    var fieldResolver = new FuncFieldResolver <NamedContentData, IReadOnlyDictionary <string, IJsonValue> >(c =>
                    {
                        return(c.Source.GetOrDefault(field.Name));
                    });

                    AddField(new FieldType
                    {
                        Name         = field.Name.ToCamelCase(),
                        Resolver     = fieldResolver,
                        ResolvedType = fieldGraphType,
                        Description  = $"The {fieldName} field."
                    });
                }
            }

            Description = $"The structure of the {schemaName} content type.";
        }