@jumpn/utils-graphql
GraphQL utilities
Types
type GqlErrorLocation = {
line: number,
column: number
};
type GqlError = {
message: string,
locations?: Array<GqlErrorLocation>
};
type GqlRequest<Variables: void | Object = void> = {
operation: string,
variables?: Variables
};
type GqlResponse<Data> = {
data?: Data,
errors?: Array<GqlError>
};
type GqlOperationType = "mutation" | "query" | "subscription";
API
errorsToString
Transforms an array of GqlError into a string.
Parameters
gqlErrors
Array<GqlError>
Examples
const gqlRespose = {
errors: [
{message: "First Error", locations: [{column: 10, line: 2}]},
{message: "Second Error", locations: [{column: 2, line: 4}]}
]
}
const error = errorsToString(gqlRespose.errors);
Returns string
getOperationType
Returns the type of the given operation
Parameters
Examples
const operation = `
subscription userSubscription($userId: ID!) {
user(userId: $userId) {
id
name
}
}
`;
const operationType = getOperationType(operation);
console.log(operationType);
Returns (void | GqlOperationType)
License
MIT :copyright: Jumpn Limited / Mauro Titimoli (mauro@jumpn.com)