Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds generic parameters to the query/mutations APIs of client #456

Merged
merged 1 commit into from
Oct 25, 2019

Conversation

ctrlplusb
Copy link
Contributor

Doing this allows me to reuse the types generated by GraphQL Code Generator to have a better typed experience via the client instance APIs.

For e.g.

import { createClient } from 'urql';
import { LoginMutation, LoginMutationVariables, LoginDocument } from '../graphql-code-generated';

const urql = createClient({ url: 'http://localhost:1234/graphql' });

urql
  .mutation<LoginMutation, LoginMutationVariables>(
    LoginDocument, 
    { email: 'foo@bar.com', password: 'baz' }
  )
  .toPromise()
  .then(result => {
    return result.data ? result.data.login.email : undefined;
  });

@ctrlplusb ctrlplusb changed the title Adds generic parameters to the query/mutations of client Adds generic parameters to the query/mutations APIs of client instance Oct 24, 2019
@ctrlplusb ctrlplusb changed the title Adds generic parameters to the query/mutations APIs of client instance Adds generic parameters to the query/mutations APIs of client Oct 24, 2019
Copy link
Collaborator

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me personally, great work on that! 👍

@andyrichardson andyrichardson merged commit 226f645 into urql-graphql:master Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants