QueryStringBuilder
Namespace: GraphQL.Query.Builder
The GraphQL query builder class.
public class QueryStringBuilder : IQueryStringBuilder
Inheritance Object → QueryStringBuilder
Implements IQueryStringBuilder
Attributes NullableContextAttribute, NullableAttribute
Fields
formatter
The property name formatter.
protected Func<PropertyInfo, string>? formatter;
ignoreCondition
The ignore condition for null/default properties.
protected QueryIgnoreCondition ignoreCondition;
Properties
QueryString
The query string builder.
public StringBuilder QueryString { get; private set; }
Property Value
Remarks:
QueryStringBuilder.Build<TSource>(IGraphQLField<TSource>) and QueryStringBuilder.BuildSelectionSet<TSource>(IGraphQLField<TSource>) each swap in their own buffer for the duration of the call, so a builder instance reused across — or nested within — several builds never accumulates the output of the previous one.
Constructors
QueryStringBuilder()
Initializes a new instance of the QueryStringBuilder class.
public QueryStringBuilder()
QueryStringBuilder(Func<PropertyInfo, String>)
Initializes a new instance of the QueryStringBuilder class.
public QueryStringBuilder(Func<PropertyInfo, string> formatter)
Parameters
formatter Func<PropertyInfo, String>
The property name formatter
QueryStringBuilder(Func<PropertyInfo, String>, QueryIgnoreCondition)
Initializes a new instance of the QueryStringBuilder class.
public QueryStringBuilder(Func<PropertyInfo, string>? formatter, QueryIgnoreCondition ignoreCondition)
Parameters
formatter Func<PropertyInfo, String>?
The property name formatter
ignoreCondition QueryIgnoreCondition
The ignore condition for null/default properties
Methods
Build<TSource>(IGraphQLField<TSource>)
Builds the query.
public string Build<TSource>(IGraphQLField<TSource> query)
Type Parameters
TSource
Parameters
query IGraphQLField<TSource>
The query.
Returns
String
The GraphQL query as string, without outer enclosing block.
BuildSelectionSet<TSource>(IGraphQLField<TSource>)
Builds the query selection set, without the enclosing braces.
public string BuildSelectionSet<TSource>(IGraphQLField<TSource> query)
Type Parameters
TSource
Parameters
query IGraphQLField<TSource>
The query.
Returns
String
The GraphQL selection set as string.
Clear()
Clears the string builder.
public void Clear()
FormatQueryParam(Object)
Formats query param.
Returns:
- null -
null - String -
"foo" - Number -
10 - Boolean -
trueorfalse - Enum -
EnumValue - DateTime -
"2024-06-15T13:45:30.0000000Z" - DateTimeOffset -
"2024-06-15T13:45:30.0000000+02:00" - TimeSpan -
"00:05:00" - Guid -
"2c1e0e0a-0000-4000-8000-000000000001" - Uri -
"https://example.com/a" - Key value pair -
foo:"bar"orfoo:10… - List -
["foo","bar"]or[1,2]… - Dictionary -
{foo:"bar",b:10} - Object -
{foo:"bar",b:10}
Objects are serialized from their public, readable, non-indexed instance properties.
protected internal virtual string FormatQueryParam(object? value)
Parameters
value Object?
Returns
String
The formatted query param.
Exceptions
InvalidDataException
Invalid Object Type in Param List
AddParams<TSource>(IGraphQLField<TSource>)
Adds query params to the query string.
protected internal void AddParams<TSource>(IGraphQLField<TSource> query)
Type Parameters
TSource
Parameters
query IGraphQLField<TSource>
The query.
AddFields<TSource>(IGraphQLField<TSource>)
Adds fields to the query sting.
protected internal void AddFields<TSource>(IGraphQLField<TSource> query)
Type Parameters
TSource
Parameters
query IGraphQLField<TSource>
The query.
Exceptions
ArgumentException
Invalid Object in Field List