Skip to the content.

< Back


GraphQLField<TSource>

Namespace: GraphQL.Query.Builder

The GraphQL field class.

public class GraphQLField<TSource> : IGraphQLField`1, IGraphQLField

Type Parameters

TSource

Inheritance ObjectGraphQLField<TSource>
Implements IGraphQLField<TSource>, IGraphQLField
Attributes NullableContextAttribute, NullableAttribute

Fields

options

The query options.

protected QueryOptions? options;

Properties

SelectList

Gets the select list.

public List<object?> SelectList { get; }

Property Value

List<Object>

Arguments

Gets the arguments.

public Dictionary<string, object?> Arguments { get; }

Property Value

Dictionary<String, Object>

Name

Gets the query name.

public string Name { get; private set; }

Property Value

String

AliasName

Gets the alias name.

public string? AliasName { get; private set; }

Property Value

String

Directives

Gets the directives attached to the field.

public List<GraphQLDirective> Directives { get; }

Property Value

List<GraphQLDirective>

Constructors

GraphQLField(String)

Initializes a new instance of the GraphQLField<TSource> class.

public GraphQLField(string name)

Parameters

name String
The field name.

Exceptions

ArgumentException
The name is not a valid GraphQL name.

GraphQLField(String, QueryOptions)

Initializes a new instance of the GraphQLField<TSource> class.

public GraphQLField(string name, QueryOptions? options)

Parameters

name String
The field name.

options QueryOptions?
The query options.

Exceptions

ArgumentException
The name is not a valid GraphQL name.

Methods

Alias(String)

Sets the query alias name.

public IGraphQLField<TSource> Alias(string alias)

Parameters

alias String
The alias name.

Returns

IGraphQLField<TSource>
The query.

Exceptions

ArgumentException
The alias is not a valid GraphQL name.

AddField<TProperty>(Expression<Func<TSource, TProperty>>)

Adds a field to the query.

public IGraphQLField<TSource> AddField<TProperty>(Expression<Func<TSource, TProperty>> selector)

Type Parameters

TProperty
The property type.

Parameters

selector Expression<Func<TSource, TProperty>>
The field selector.

Returns

IGraphQLField<TSource>
The query.

AddField(String)

Adds a field to the query.

public IGraphQLField<TSource> AddField(string field)

Parameters

field String
The field name.

Returns

IGraphQLField<TSource>
The query.

AddField<TSubSource>(Expression<Func<TSource, TSubSource>>, Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>>)

Adds a sub-object field to the query.

public IGraphQLField<TSource> AddField<TSubSource>(Expression<Func<TSource, TSubSource>> selector, Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>> build) where TSubSource : class

Type Parameters

TSubSource
The sub-object type.

Parameters

selector Expression<Func<TSource, TSubSource>>
The field selector.

build Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>>
The sub-object query building function.

Returns

IGraphQLField<TSource>
The query.

AddField<TSubSource>(Expression<Func<TSource, IEnumerable<TSubSource>>>, Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>>)

Adds a sub-list field to the query.

public IGraphQLField<TSource> AddField<TSubSource>(Expression<Func<TSource, IEnumerable<TSubSource>>> selector, Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>> build) where TSubSource : class

Type Parameters

TSubSource
The sub-list object type.

Parameters

selector Expression<Func<TSource, IEnumerable<TSubSource>>>
The field selector.

build Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>>
The sub-object query building function.

Returns

IGraphQLField<TSource>
The query.

AddField<TSubSource>(String, Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>>)

Adds a sub-object field to the query.

public IGraphQLField<TSource> AddField<TSubSource>(string field, Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>> build) where TSubSource : class

Type Parameters

TSubSource
The sub-object type.

Parameters

field String
The field name.

build Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>>
The sub-object query building function.

Returns

IGraphQLField<TSource>
The query.

AddField<TProperty>(Expression<Func<TSource, TProperty>>, params GraphQLDirective[])

Adds a field to the query with directives.

public IGraphQLField<TSource> AddField<TProperty>(Expression<Func<TSource, TProperty>> selector, params GraphQLDirective[] directives)

Type Parameters

TProperty

Parameters

selector Expression<Func<TSource, TProperty>>

params directives GraphQLDirective[]

Returns

IGraphQLField<TSource>

AddField(String, params GraphQLDirective[])

Adds a field to the query with directives.

public IGraphQLField<TSource> AddField(string field, params GraphQLDirective[] directives)

Parameters

field String

params directives GraphQLDirective[]

Returns

IGraphQLField<TSource>

AddField<TSubSource>(Expression<Func<TSource, TSubSource>>, Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>>, params GraphQLDirective[])

Adds a sub-object field to the query with directives.

public IGraphQLField<TSource> AddField<TSubSource>(Expression<Func<TSource, TSubSource>> selector, Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>> build, params GraphQLDirective[] directives) where TSubSource : class

Type Parameters

TSubSource

Parameters

selector Expression<Func<TSource, TSubSource>>

build Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>>

params directives GraphQLDirective[]

Returns

IGraphQLField<TSource>

AddField<TSubSource>(Expression<Func<TSource, IEnumerable<TSubSource>>>, Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>>, params GraphQLDirective[])

Adds a sub-list field to the query with directives.

public IGraphQLField<TSource> AddField<TSubSource>(Expression<Func<TSource, IEnumerable<TSubSource>>> selector, Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>> build, params GraphQLDirective[] directives) where TSubSource : class

Type Parameters

TSubSource

Parameters

selector Expression<Func<TSource, IEnumerable<TSubSource>>>

build Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>>

params directives GraphQLDirective[]

Returns

IGraphQLField<TSource>

AddField<TSubSource>(String, Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>>, params GraphQLDirective[])

Adds a sub-object field to the query with directives.

public IGraphQLField<TSource> AddField<TSubSource>(string field, Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>> build, params GraphQLDirective[] directives) where TSubSource : class

Type Parameters

TSubSource

Parameters

field String

build Func<IGraphQLField<TSubSource>, IGraphQLField<TSubSource>>

params directives GraphQLDirective[]

Returns

IGraphQLField<TSource>

AddFragment(GraphQLFragment)

Adds a fragment spread to the query.

public IGraphQLField<TSource> AddFragment(GraphQLFragment fragment)

Parameters

fragment GraphQLFragment

Returns

IGraphQLField<TSource>

AddUnion<TUnionType>(String, Func<IGraphQLField<TUnionType>, IGraphQLField<TUnionType>>)

Adds an union to the query.

public IGraphQLField<TSource> AddUnion<TUnionType>(string typeName, Func<IGraphQLField<TUnionType>, IGraphQLField<TUnionType>> build) where TUnionType : class, TSource

Type Parameters

TUnionType
The union type.

Parameters

typeName String
The union type name.

build Func<IGraphQLField<TUnionType>, IGraphQLField<TUnionType>>
The union building function.

Returns

IGraphQLField<TSource>
The query.

Exceptions

ArgumentException
The type name is not a valid GraphQL name.

AddUnion<TUnionType>(Func<IGraphQLField<TUnionType>, IGraphQLField<TUnionType>>)

Adds an union to the query.

public IGraphQLField<TSource> AddUnion<TUnionType>(Func<IGraphQLField<TUnionType>, IGraphQLField<TUnionType>> build) where TUnionType : class, TSource

Type Parameters

TUnionType
The union type.

Parameters

build Func<IGraphQLField<TUnionType>, IGraphQLField<TUnionType>>
The union building function.

Returns

IGraphQLField<TSource>
The query.

AddArgument(String, Object)

Adds a new argument to the query.

public IGraphQLField<TSource> AddArgument(string key, object? value)

Parameters

key String
The argument name.

value Object?
The value.

Returns

IGraphQLField<TSource>
The query.

AddArguments(Dictionary<String, Object>)

Adds arguments to the query.

public IGraphQLField<TSource> AddArguments(Dictionary<string, object?> arguments)

Parameters

arguments Dictionary<String, Object>
the dictionary argument.

Returns

IGraphQLField<TSource>
The query.

AddArguments<TArguments>(TArguments)

Adds arguments to the query.

public IGraphQLField<TSource> AddArguments<TArguments>(TArguments arguments) where TArguments : class

Type Parameters

TArguments
The arguments object type.

Parameters

arguments TArguments
The arguments object.

Returns

IGraphQLField<TSource>
The query.

Build()

Builds the query.

public string Build()

Returns

String
The GraphQL query as string, without outer enclosing block.

Exceptions

ArgumentException
Must have a ‘Name’ specified in the Query

ArgumentException
Must have a one or more ‘Select’ fields in the Query

BuildSelectionSet()

Builds the field selection set, without the enclosing braces.

public string BuildSelectionSet()

Returns

String
The GraphQL selection set as string.


< Back