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

Export types and classes needed #64

Merged

Conversation

bakerac4
Copy link
Contributor

@bakerac4 bakerac4 commented May 17, 2022

Fixes #63 and #58

@netlify
Copy link

netlify bot commented May 17, 2022

👷 Deploy request for glimmer-apollo pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 39fecee

@josemarluedke
Copy link
Owner

Hi @bakerac4!

We currently export a few type utilities that allow us to make custom queries / pre-defined queries. Exports are here: https://github.com/josemarluedke/glimmer-apollo/blob/main/packages/glimmer-apollo/src/-private/usables.ts

Wouldn't that be enough?

Here is an usage example:

import { gql, useQuery } from 'glimmer-apollo';
import type { UseQuery } from 'glimmer-apollo';
import type {
  MyQuery,
  MyQueryQueryVariables
} from './my-graphql-types';

export function useMyQuery<
  T extends UseQuery<
    MyQuery,
   MyQueryQueryVariables 
  >
>(ctx: Object, args?: T['args']): T['return'] {
  return useQuery(ctx, () => [
    gql`
      query MyQuery($id: ID!) {
        myQuery(id: $id) {
          id
        }
      }
    `,
    args ? args() : {}
  ]);
}

@josemarluedke
Copy link
Owner

@bakerac4 I love the custom resource tests, can you rework that to use the type utilities I mentioned above?

@bakerac4
Copy link
Contributor Author

bakerac4 commented May 18, 2022

@josemarluedke I believe that fixes part of the issue with types. But for our generic query that sets defaults, you don't have the query type.

  T extends UseQuery<
    **GenericQuery**,
   **GenericQueryVariables** 
  >
>(ctx: Object, query: **WhatsThisType**, args?: T['args']): T['return'] {
  return useQuery(ctx, () => [
    query,
    args ? args() : {}
  ]);
}

@josemarluedke josemarluedke merged commit bcd8b22 into josemarluedke:main May 20, 2022
@josemarluedke
Copy link
Owner

@bakerac4 Thanks for working on this.

@josemarluedke josemarluedke added the Type: Enhancement This is changing something existing label May 23, 2022
@josemarluedke
Copy link
Owner

Released in v0.5.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement This is changing something existing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to create custom resources
2 participants