Function skeetGraphql

  • Executes a GraphQL query against a given endpoint.

    Type Parameters

    • T

      The expected return type of the GraphQL query.

    • V

      The type of the variables used in the GraphQL query.

    Parameters

    • accessToken: string

      The access token for authentication.

    • endpoint: string

      The endpoint URL for the GraphQL server.

    • query: string

      The GraphQL query to execute.

    • variables: V = ...

      Optional variables to be used in the GraphQL query.

    Returns Promise<T>

    • Returns a promise that resolves to the result of the GraphQL query.

    Throws

    Will throw an error if the GraphQL query fails.

    Example

    const query: CreateUserQuery = `mutation Mutation(
    $uid: String
    $username: String
    $email: String
    $iconUrl: String
    ) {
    createUser(uid: $uid, username: $username, email: $email, iconUrl: $iconUrl) {
    id
    rawId
    uid
    username
    email
    iconUrl
    role
    iv
    createdAt
    updatedAt
    }
    }`
    const accessToken = 'your_access_token'
    const variables: CreateUserParams = {
    uid: 'your_uid',
    username: 'your_username',
    email: 'your_email',
    iconUrl: 'your_icon_url',
    }






    const endpoint = 'https://your-production-endpoint.com/graphql'

    const user = await skeetGraphql<UserType, CreateUserParams>(accessToken, endpoint, query, variables)
    console.log(user)

Generated using TypeDoc