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

Expose standardGraphQLHandlers to type graphql.link #1509

Open
1 task
R4YM3 opened this issue Dec 30, 2022 · 4 comments · May be fixed by #2357
Open
1 task

Expose standardGraphQLHandlers to type graphql.link #1509

R4YM3 opened this issue Dec 30, 2022 · 4 comments · May be fixed by #2357
Labels

Comments

@R4YM3
Copy link

R4YM3 commented Dec 30, 2022

Scope

Adds a new behavior

Compatibility

  • This is a breaking change

Feature description

First of all, thanks for this amazing library.

I am trying the following:

import handlers from './handlers.ts'

export const getMswWorker = () => setupWorker(...handlers);

handlers.ts:

import someQuery from './someQuery.ts'

const service = graphql.link("https://www.website.com/graphql");

export default [
  ...someQuery(service),
]

someQuery.ts:

export default (service: standardGraphQLHandlers) => [
  service.query(USEFEATURE_OPERATIONNAME, (req, res, ctx) => {
    return res(
      ctx.data({
        foo: 'bar'
      })
    );
  })
]

In this last codeblock i need to type graphql.link, which is i believe standardGraphQLHandlers.
Only this type is not exposed.

Feature request: expose standardGraphQLHandlers type.

@R4YM3 R4YM3 added the feature label Dec 30, 2022
@tdraper-dev
Copy link

Also running into needing the same type exposed:


The inferred type of 'storefrontLink' cannot be named without a reference to 'msw/node_modules/graphql'. This is likely not portable. A type annotation is necessary.ts(2742)

@kettanaito
Copy link
Member

Hey, @R4YM3. Thanks for raising this.

standardGraphQLHandlers is a part of the internal logic and I wouldn't expose it, as it doesn't provide any runtime value for the end consumer of the library. This needs a proper solution, I will try to think of one.

For the time being, I can suggest annotating your someQuery.ts like this:

import { graphql } from 'msw'

type StandardGraphQLHandlers = Omit<typeof graphql, 'link'>

export default (service: StandardGraphQLHandlers) => { /* ... */ }

Since graphql is a composition of standard handlers and link(), this should give you the same result type-wise.

@tdraper-dev
Copy link

@kettanaito

Another reason to love msw, fantastic communication.

Thanks so much!

@R4YM3
Copy link
Author

R4YM3 commented Jan 21, 2023

@kettanaito great, thanks for the suggestion.
This will help me forward.

Keep up the good work.

@kettanaito kettanaito linked a pull request Nov 15, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants