Class GraphQLResponse

Namespace
ProtoTest.GraphQL
Assembly
ProtoTest.GraphQL.dll
public sealed class GraphQLResponse : ProtoHttpResponse, IDisposable
Inheritance
GraphQLResponse
Implements
Inherited Members
Extension Methods

Properties

Data

public JsonElement? Data { get; }

Property Value

JsonElement?

Errors

public IReadOnlyList<GraphQLError> Errors { get; }

Property Value

IReadOnlyList<GraphQLError>

Extensions

public JsonElement? Extensions { get; }

Property Value

JsonElement?

HasData

public bool HasData { get; }

Property Value

bool

HasErrors

public bool HasErrors { get; }

Property Value

bool

SelectedData

The selected root-field value for shape-driven operations; otherwise the complete data object.

public JsonElement? SelectedData { get; }

Property Value

JsonElement?

Should

The positive assertions on this response, such as Should.HaveHttpStatus(...) and Should.MatchShape(...).

public GraphQLShouldAssertions Should { get; }

Property Value

GraphQLShouldAssertions

ShouldNot

Assertions that must not hold, such as ShouldNot.HaveHttpStatus(...) or ShouldNot.HaveErrors(). A negated shape match is not meaningful, so shape lives on Should.

public GraphQLAssertions ShouldNot { get; }

Property Value

GraphQLAssertions

Methods

Dispose()

Disposes the parsed document and then the underlying HTTP response.

public override void Dispose()

ReadDataAs<T>(string, JsonSerializerOptions?)

Reads a single value from the selected data at jsonPath and deserializes it as T, for example ReadDataAs<int>("$.order.total"). The supported subset is $, dot members and [n] indices (see JsonPathResolver); a leading member without $ is accepted. A response with no data returns default; a path that does not resolve throws GraphQLAssertionException naming the operation and the path.

public T? ReadDataAs<T>(string jsonPath, JsonSerializerOptions? options = null)

Parameters

jsonPath string
options JsonSerializerOptions

Returns

T

Type Parameters

T

ReadDataAs<T>(JsonSerializerOptions?)

Deserializes the selected data as T, or returns default when the response has no data. A failure records a graphql.response.deserialize operation and rethrows.

public T? ReadDataAs<T>(JsonSerializerOptions? options = null)

Parameters

options JsonSerializerOptions

Returns

T

Type Parameters

T

ReadRequired<T>(string, JsonSerializerOptions?)

Reads the value at jsonPath as T and fails when the response has no data or the path holds JSON null, for every T including value types, because the null check runs before the deserializer. A path that does not resolve fails through ReadDataAs<T>(string, JsonSerializerOptions?) with the operation and the path.

public T ReadRequired<T>(string jsonPath, JsonSerializerOptions? options = null)

Parameters

jsonPath string
options JsonSerializerOptions

Returns

T

Type Parameters

T

ReadRequired<T>(JsonSerializerOptions?)

Reads the selected data as T and fails when there is nothing to return: a response without data, or data that is JSON null, throws GraphQLAssertionException naming the operation instead of returning default. Use it where the value is required; ReadDataAs<T>(JsonSerializerOptions?) stays nullable.

public T ReadRequired<T>(JsonSerializerOptions? options = null)

Parameters

options JsonSerializerOptions

Returns

T

Type Parameters

T

ShouldHaveError(string)

Asserts a GraphQL error carries code in extensions.code.

[Obsolete("Use response.Should.HaveError(code) instead.")]
public GraphQLResponse ShouldHaveError(string code)

Parameters

code string

Returns

GraphQLResponse

Remarks

Obsolete: use response.Should.HaveError(code).

ShouldHaveErrors()

Asserts the response carries at least one GraphQL error.

[Obsolete("Use response.Should.HaveErrors() instead.")]
public GraphQLResponse ShouldHaveErrors()

Returns

GraphQLResponse

Remarks

Obsolete: use response.Should.HaveErrors().

ShouldHaveNoErrors()

Asserts the response carries no GraphQL errors.

[Obsolete("Use response.Should.HaveNoErrors() instead.")]
public GraphQLResponse ShouldHaveNoErrors()

Returns

GraphQLResponse

Remarks

Obsolete: use response.Should.HaveNoErrors().

ShouldMatchShape(object, JsonSerializerOptions?)

Matches the selected data against an expected shape through the same matcher REST, GraphQL, gRPC and messaging share.

[Obsolete("Use response.Should.MatchShape(shape) instead.")]
public GraphQLResponse ShouldMatchShape(object expectedShape, JsonSerializerOptions? options = null)

Parameters

expectedShape object
options JsonSerializerOptions

Returns

GraphQLResponse

Remarks

Obsolete: use response.Should.MatchShape(shape).