karanpratapsingh / fullstack-starterkit

GraphQL first full-stack starter kit with Node, React. Powered by TypeScript
MIT License
1.17k stars 100 forks source link

Feature/graphql react codegen #16

Closed karanpratapsingh closed 4 years ago

karanpratapsingh commented 4 years ago

CHANGELOG

Now with the generated web/src/types/graphql.tsx we can simply use typesafe query/mutation hooks generated from backend/packages/graphql/api rather than declaring twice (on web and backend)

Example:

import { GET_USER_QUERY } from '@web/graphql';

const variables = {
  input: {
    id: 'demo_user_id'
  }
};

const { data, loading, error } = useQuery(GET_USER_QUERY, { variables });

The above can now be written as:

import { useGetUserQuery } from '@web/graphql';

const variables = {
  input: {
    id: 'demo_user_id'
  }
};

const { data, loading, error } = useGetUserQuery({ variables });

Thanks to @capaj for suggesting this improvement

capaj commented 4 years ago

thanks @karanpratapsingh. This is a great improvement.

karanpratapsingh commented 4 years ago

Glad you liked it 😁