reactive/data-client

GraphQL ergonomics

Closed this issue · 2 comments

This is explore possible ergonomics improvements to GraphQL support. For context, the initial library was built to support 100% of the powers of Rest Hooks high performance high data integrity with helpers built on the low level API. To expand upon GraphQL support more specializations can be created on top of. These of course will always be completely optional.

https://ntucker.notion.site/GQLResource-3879592f59a044f5a461f91ed0cbfb9e

Before

export const userDetail = gql.query(
  (v: { name: string }) => `query UserDetail($name: String!) {
    user(name: $name) {
      id
      name
      email
    }
  }`,
  { user: User },
);

After

export const userDetail = gql.query(
  'user ',
  { name: 'String' },
  User,
);

Before

const createReview = gql.mutation(
  (v: {
    ep: string;
    review: { stars: number; commentary: string };
  }) => `mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
    createReview(episode: $ep, review: $review) {
      stars
      commentary
    }
  }`,
  { createReview: Review },
);

After

const createReview = gql.mutation(
  'createReview',
 { episode; 'Episode!', review: 'ReviewInput!' },
  Review,
);

Types can be registered in the construction of base endpoint

const gql = new GQLEndpoint(
  'https://swapi-graphql.netlify.app/.netlify/functions/index',
 { schema: { 'ReviewInput': { stars: 'Number', commentary: 'String' } }},
);

Closing in favor of discussion: #2403