This website covers the upcoming v3 alpha. For v2 docs, see our previous website.
Use Cases

resolve() - The Promise Interface

In GQty core, the resolve() method gives you a promise interface to work with all query types. i.e. Query, Mutation and Subscription are supported.


For example, imagine you have this GraphQL schema at server side:

type Query {
  me: User!
type User {
  firstName: String!
  lastName: String!
  email: String!
  image: Image!
  friends(first: Int, last: Int): [User!]!
  updatedAt: Int!
type Image {
  alt: String!
  src: String!

We can then construct our query like this:

Customizing responses

You may customize the response object by returning a new object from the selection function.

import { resolve } from "~/gqty";
const data = await resolve(({ query: { me } }) => ({
  fullName: `${me.firstName} ${me.lastName}`,

Querying with arguments

In the examples above, destructuring syntax are used to make it look as close to a GraphQL query as possible. But when the query includes arguments, you should instead bring it down to the function body.

import { resolve } from "~/gqty";
const selectUser = (user: User) => ({
  fullName: `${user.firstName} ${user.lastName}`,
const data = await resolve(({ query: { me } }) => ({
  myFriends: friends({ first: 10 }).map(selectUser),
Arguments are aliased

GQty automatically create alias by hashing the arguments, you can return from the selection function to compose your own data shape without knowing the hash ahead of time.


Mutations are similar to queries, but you use the mutation type instead of query.

type Mutation {
  updateProfile(firstName: String, lastName: String): User!
Pure functions only

Input values must not change between invocations, the provided function will be called a second time to access the fetched data from the cache.


The resolve function wraps GraphQL subscriptions into a promise-like interface. Subscriptions created via resolve() will be closed upon receiving initial data, i.e. the first next message.

type Subscription {
  onProfileUpdate: User!

For a complete list of available options, check out the API Reference.