Beispiel #1
0
        public ContentGraphType(Schema schema, IGraphQLContext context)
        {
            this.schema  = schema;
            this.context = context;

            Name = $"{schema.Name.ToPascalCase()}Dto";
        }
Beispiel #2
0
        private void AddAssetFind(IGraphQLContext graphQLContext)
        {
            AddField(new FieldType
            {
                Name      = "findAsset",
                Arguments = new QueryArguments
                {
                    new QueryArgument(typeof(StringGraphType))
                    {
                        Name         = "id",
                        Description  = "The id of the asset.",
                        DefaultValue = string.Empty
                    }
                },
                ResolvedType = graphQLContext.GetAssetType(),
                Resolver     = new FuncFieldResolver <object>(c =>
                {
                    var context   = (GraphQLQueryContext)c.UserContext;
                    var contentId = Guid.Parse(c.GetArgument("id", Guid.Empty.ToString()));

                    return(context.FindAssetAsync(contentId));
                }),
                Description = "Find an asset by id."
            });
        }
Beispiel #3
0
        public ContentGraphType(ISchemaEntity schemaEntity, IGraphQLContext context)
        {
            this.context      = context;
            this.schemaEntity = schemaEntity;

            Name = $"{schemaEntity.Name.ToPascalCase()}Dto";
        }
Beispiel #4
0
        public ContentQueryGraphType(IGraphQLContext graphQLContext, IEnumerable <ISchemaEntity> schemas)
        {
            AddAssetFind(graphQLContext);
            AddAssetsQuery(graphQLContext);

            foreach (var schema in schemas)
            {
                var schemaName = schema.SchemaDef.Properties.Label.WithFallback(schema.SchemaDef.Name);
                var schemaType = graphQLContext.GetSchemaType(schema.Id);

                AddContentFind(schema, schemaType, schemaName);
                AddContentQuery(schema, schemaType, schemaName);
            }

            Description = "The app queries.";
        }
Beispiel #5
0
        public ContentDataGraphType(Schema schema, IGraphQLContext context)
        {
            var schemaName = schema.Properties.Label.WithFallback(schema.Name);

            Name = $"{schema.Name.ToPascalCase()}DataDto";

            foreach (var field in schema.Fields.Where(x => !x.IsHidden))
            {
                var fieldInfo = context.GetGraphType(field);

                if (fieldInfo.ResolveType != null)
                {
                    var fieldName = field.RawProperties.Label.WithFallback(field.Name);

                    var fieldGraphType = new ObjectGraphType
                    {
                        Name = $"{schema.Name.ToPascalCase()}Data{field.Name.ToPascalCase()}Dto"
                    };

                    var partition = context.ResolvePartition(field.Paritioning);

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

                    fieldGraphType.Description = $"The 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 structure of a {schemaName} content type.";
        }
Beispiel #6
0
        private void AddAssetsQuery(IGraphQLContext graphQLContext)
        {
            AddField(new FieldType
            {
                Name      = "queryAssets",
                Arguments = new QueryArguments
                {
                    new QueryArgument(typeof(IntGraphType))
                    {
                        Name         = "top",
                        Description  = "Optional number of assets to take.",
                        DefaultValue = 20
                    },
                    new QueryArgument(typeof(IntGraphType))
                    {
                        Name         = "skip",
                        Description  = "Optional number of assets to skip.",
                        DefaultValue = 0
                    },
                    new QueryArgument(typeof(StringGraphType))
                    {
                        Name         = "search",
                        Description  = "Optional query.",
                        DefaultValue = string.Empty
                    }
                },
                ResolvedType = new ListGraphType(new NonNullGraphType(graphQLContext.GetAssetType())),
                Resolver     = new FuncFieldResolver <object>(c =>
                {
                    var context = (GraphQLQueryContext)c.UserContext;

                    var argTop   = c.GetArgument("top", 20);
                    var argSkip  = c.GetArgument("skip", 0);
                    var argQuery = c.GetArgument("search", string.Empty);

                    return(context.QueryAssetsAsync(argQuery, argSkip, argTop));
                }),
                Description = "Query assets items."
            });
        }
Beispiel #7
0
        public AssetGraphType(IGraphQLContext context)
        {
            Name = "AssetDto";

            AddField(new FieldType
            {
                Name         = "id",
                Resolver     = Resolver(x => x.Id.ToString()),
                ResolvedType = new NonNullGraphType(new StringGraphType()),
                Description  = "The id of the asset."
            });

            AddField(new FieldType
            {
                Name         = "version",
                Resolver     = Resolver(x => x.Version),
                ResolvedType = new NonNullGraphType(new IntGraphType()),
                Description  = "The version of the asset."
            });

            AddField(new FieldType
            {
                Name         = "created",
                Resolver     = Resolver(x => x.Created.ToDateTimeUtc()),
                ResolvedType = new NonNullGraphType(new DateGraphType()),
                Description  = "The date and time when the asset has been created."
            });

            AddField(new FieldType
            {
                Name         = "createdBy",
                Resolver     = Resolver(x => x.CreatedBy.ToString()),
                ResolvedType = new NonNullGraphType(new StringGraphType()),
                Description  = "The user that has created the asset."
            });

            AddField(new FieldType
            {
                Name         = "lastModified",
                Resolver     = Resolver(x => x.LastModified.ToDateTimeUtc()),
                ResolvedType = new NonNullGraphType(new DateGraphType()),
                Description  = "The date and time when the asset has been modified last."
            });

            AddField(new FieldType
            {
                Name         = "lastModifiedBy",
                Resolver     = Resolver(x => x.LastModifiedBy.ToString()),
                ResolvedType = new NonNullGraphType(new StringGraphType()),
                Description  = "The user that has updated the asset last."
            });

            AddField(new FieldType
            {
                Name         = "mimeType",
                Resolver     = Resolver(x => x.MimeType),
                ResolvedType = new NonNullGraphType(new StringGraphType()),
                Description  = "The mime type."
            });

            AddField(new FieldType
            {
                Name         = "url",
                Resolver     = context.ResolveAssetUrl(),
                ResolvedType = new NonNullGraphType(new StringGraphType()),
                Description  = "The url to the asset."
            });

            AddField(new FieldType
            {
                Name         = "thumbnailUrl",
                Resolver     = context.ResolveAssetThumbnailUrl(),
                ResolvedType = new StringGraphType(),
                Description  = "The thumbnail url to the asset."
            });

            AddField(new FieldType
            {
                Name         = "fileName",
                Resolver     = Resolver(x => x.FileName),
                ResolvedType = new NonNullGraphType(new StringGraphType()),
                Description  = "The file name."
            });

            AddField(new FieldType
            {
                Name         = "fileType",
                Resolver     = Resolver(x => x.FileName.FileType()),
                ResolvedType = new NonNullGraphType(new StringGraphType()),
                Description  = "The file type."
            });

            AddField(new FieldType
            {
                Name         = "fileSize",
                Resolver     = Resolver(x => x.FileSize),
                ResolvedType = new NonNullGraphType(new IntGraphType()),
                Description  = "The size of the file in bytes."
            });

            AddField(new FieldType
            {
                Name         = "fileVersion",
                Resolver     = Resolver(x => x.FileVersion),
                ResolvedType = new NonNullGraphType(new IntGraphType()),
                Description  = "The version of the file."
            });

            AddField(new FieldType
            {
                Name         = "isImage",
                Resolver     = Resolver(x => x.IsImage),
                ResolvedType = new NonNullGraphType(new BooleanGraphType()),
                Description  = "Determines of the created file is an image."
            });

            AddField(new FieldType
            {
                Name         = "pixelWidth",
                Resolver     = Resolver(x => x.PixelWidth),
                ResolvedType = new IntGraphType(),
                Description  = "The width of the image in pixels if the asset is an image."
            });

            AddField(new FieldType
            {
                Name         = "pixelHeight",
                Resolver     = Resolver(x => x.PixelHeight),
                ResolvedType = new IntGraphType(),
                Description  = "The height of the image in pixels if the asset is an image."
            });

            if (context.CanGenerateAssetSourceUrl)
            {
                AddField(new FieldType
                {
                    Name         = "sourceUrl",
                    Resolver     = context.ResolveAssetSourceUrl(),
                    ResolvedType = new StringGraphType(),
                    Description  = "The source url of the asset."
                });
            }

            Description = "An asset";
        }