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

[graphiql] optional fetcher, user network configuration tab #2795

Open
acao opened this issue Oct 8, 2022 · 1 comment
Open

[graphiql] optional fetcher, user network configuration tab #2795

acao opened this issue Oct 8, 2022 · 1 comment
Labels
enhancement graphiql plugin proposal GraphiQL Plugin Proposal for review potential plugin A potential plugin idea for later versions of GraphiQL

Comments

@acao
Copy link
Member

acao commented Oct 8, 2022

A long requested feature, and what we envisioned for the sidebar plugin ecosystem a few years ago, is a place where users can configure their environments and settings for each environment

the network tab would provide a global setting for:

the network tab would provide per-environment settings for:

  • url
  • default initial headers for each operation (that would show up in the headers tab)
  • HTTP POST or GET for queries? http spec
  • whether to persist the headers for that environment

How will this impact GraphiQL?

  • fetcher becomes optional if environments prop is provided
  • environments prop looks like graphql-config object but maybe stricter (difficult to normalise every pattern)
  • @graphiql/toolkit createGraphiQLFetcher() becomes an internal detail if environments prop is provided?
@acao acao changed the title [graphiql] user network configuration tab [graphiql] optional fetcher, user network configuration tab Oct 10, 2022
@acao acao added potential plugin A potential plugin idea for later versions of GraphiQL plugin proposal GraphiQL Plugin Proposal for review labels Nov 26, 2022
@acao acao pinned this issue Jul 30, 2023
@acao
Copy link
Member Author

acao commented Aug 1, 2023

Updated Proposal

Making URL a potentially internal state is the most important outcome. Other plugins can manage multiple projects,

First, the props will contain a discriminated union:

type FetcherFirst = {
 url?: string,
 subscriptionsUrl?: string
 fetcher: Fetcher
}

type UrlFirst = {
 url: string,
 subscriptionsUrl?: string
 fetcher?: Fetcher
}

FetcherFirst | UrlFirst

url state becomes a potentially dynamic internal detail:

const fetcher: Fetcher = async (graphQLParams, options) => {
  const data = await fetch(
   options.url,
    {
      method: 'POST',
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
        ...options.headers,
      },
      body: JSON.stringify(graphQLParams),
      credentials: 'same-origin',
    },
  );
  return data.json().catch(() => data.text());
};

Context Changes:

url becomes an optional parameter to SchemaContext, which is called up when building ExecutionContext

createGraphiQLFetcher() change

url becomes an optional parameter, as this may become a dynamically supplied options.url parameter

fetcher and no url:

assumes the user has statically provided a URL to the fetcher

fetcher and url

fetcher passes url as a dynamic parameter, for example in createGraphiQLFetcher()

url and no fetcher:

url is used to generate a fetcher using createGraphiQLFetcher()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement graphiql plugin proposal GraphiQL Plugin Proposal for review potential plugin A potential plugin idea for later versions of GraphiQL
Projects
Status: Todo
Development

No branches or pull requests

1 participant