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

Type error: FetcherParams.variables declared as string but actually passed as object #1632

Closed
swsnr opened this issue Aug 5, 2020 · 4 comments
Labels

Comments

@swsnr
Copy link

swsnr commented Aug 5, 2020

GraphiQL 1.0.3 declares FetcherParams.variables as string, see GraphiQL.tsx#L75, presumably containing the string value from the variables editor

However in a custom fetcher I actually get a Javascript object (which seems to be intended).

You can easily reproduce this with:

<html>

<head>
  <title>Simple GraphiQL Example</title>
  <link href="https://unpkg.com/graphiql/graphiql.min.css" rel="stylesheet" />
</head>

<body style="margin: 0;">
  <div id="graphiql" style="height: 100vh;"></div>

  <script crossorigin src="https://unpkg.com/react/umd/react.production.min.js"></script>
  <script crossorigin src="https://unpkg.com/react-dom/umd/react-dom.production.min.js"></script>
  <script crossorigin src="https://unpkg.com/graphiql/graphiql.min.js"></script>

  <script>
    const graphQLFetcher = graphQLParams => {
      const variables = graphQLParams.variables;
      console.debug('Variables', graphQLParams.variables/*  */)
      if (variables && typeof graphQLParams.variables !== "string") {
        throw new Error("variables not a string!");
      }
      return new Promise((resolve) => resolve("Hello world"));
    };
    ReactDOM.render(
      React.createElement(GraphiQL, { fetcher: graphQLFetcher }),
      document.getElementById('graphiql'),
    );
  </script>
</body>

</html>
@acao acao added bug and removed bug labels Aug 5, 2020
@acao
Copy link
Member

acao commented Aug 5, 2020

oh my bad, i see what you're saying. this is an issue from the typescript migration in january. just need to update it,

@acao acao closed this as completed Aug 5, 2020
@acao acao added bug graphiql and removed bug labels Aug 5, 2020
@acao acao reopened this Aug 5, 2020
acao added a commit that referenced this issue Aug 5, 2020
need to make sure `variables` is typed as any, since it comes in as an object literal, not a string. resolves #1632
acao added a commit that referenced this issue Aug 5, 2020
need to make sure `variables` is typed as any, since it comes in as an object literal, not a string. resolves #1632
@acao acao closed this as completed Aug 9, 2020
@acao
Copy link
Member

acao commented Aug 9, 2020

will release this shortly!

@swsnr
Copy link
Author

swsnr commented Aug 16, 2020

@acao Did you release this already?

@acao
Copy link
Member

acao commented Aug 17, 2020

sorry no, there are issues in the pipeline. we have to do some heavy lifting to keep cutting graphiql 1 releases from the main branch now, and I'm going to be away from work on vacation (starting today), so it will be a few PRs and some time until we can issue another graphiql 1 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants