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

feat: add @graphiql/react package #2370

Merged
merged 13 commits into from
May 13, 2022

Conversation

thomasheyenbrock
Copy link
Collaborator

This PR adds a new package @graphiql/react to the monorepo. The idea for this package is to provide all the building blocks (context providers, hooks to work with the state managed by the context, reusable components, etc.) for building a GraphiQL-like UI. The main graphiql package will become the reference implementation for how to use the components from @graphiql/react.

As a first step towards this goal, we add the following to the new package:

  • A React context ExplorerContext that shall contain all the state and logic related to the docs/explorer. We wrap with in a component ExplorerContextProvider that has to be rendered at the top of the tree that contains other GraphiQL-components that need to access or change this state.
  • For easy access in functional components we provide a hook useExplorerNavStack.
  • We also export the context itself, so that we can use consumer components to access the state in legacy class components.

Notes:

  • I needed to update the eslint-plugin-react version, otherwise using the plugin:react/jsx-runtime did not work.
  • I fixed a minor type issue where GraphQLType was used instead of the SchemaReference type from codemirror-graphql.

@changeset-bot
Copy link

changeset-bot bot commented Apr 21, 2022

🦋 Changeset detected

Latest commit: 6e8a3e5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
graphiql Minor
@graphiql/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@timsuchanek
Copy link
Member

Awesome! I'll have a look in a bit!

Regarding eslint, we should get https://github.com/graphql/graphiql/pulls/B2o5T merged, they might even resolve some issues?

Copy link
Member

@timsuchanek timsuchanek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I like the cleanup around state, not having parent components dealing with child state anymore, but instead using the context.
The only thing is cleaning up the merge conflicts, apart from that good to go!

@timsuchanek timsuchanek mentioned this pull request May 9, 2022
7 tasks
@thomasheyenbrock thomasheyenbrock force-pushed the feat/graphiql-react branch 2 times, most recently from ace212a to f006a54 Compare May 11, 2022 20:51
@codecov
Copy link

codecov bot commented May 11, 2022

Codecov Report

Merging #2370 (6e8a3e5) into main (2d91916) will decrease coverage by 0.64%.
The diff coverage is 69.20%.

@@            Coverage Diff             @@
##             main    #2370      +/-   ##
==========================================
- Coverage   65.70%   65.06%   -0.65%     
==========================================
  Files          85       81       -4     
  Lines        5106     5255     +149     
  Branches     1631     1698      +67     
==========================================
+ Hits         3355     3419      +64     
- Misses       1747     1832      +85     
  Partials        4        4              
Impacted Files Coverage Δ
packages/codemirror-graphql/src/hint.ts 94.73% <ø> (ø)
packages/codemirror-graphql/src/lint.ts 100.00% <ø> (ø)
packages/codemirror-graphql/src/results/mode.ts 47.05% <ø> (ø)
...kages/codemirror-graphql/src/utils/forEachState.ts 100.00% <ø> (ø)
packages/codemirror-graphql/src/utils/hintList.ts 95.65% <ø> (ø)
...ackages/codemirror-graphql/src/utils/info-addon.ts 1.02% <ø> (ø)
...ckages/codemirror-graphql/src/utils/mode-indent.ts 0.00% <0.00%> (ø)
packages/codemirror-graphql/src/variables/hint.ts 89.70% <ø> (ø)
packages/codemirror-graphql/src/variables/mode.ts 79.48% <ø> (ø)
...aphiql/src/components/DocExplorer/DefaultValue.tsx 50.00% <ø> (ø)
... and 85 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5696df...6e8a3e5. Read the comment docs.

Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@acao
Copy link
Member

acao commented May 13, 2022

this is a great start for @graphiql/react! what do you think of moving the DocExplorer components to @graphiql/react workspace as well?

} from 'graphql';
import copyToClipboard from 'copy-to-clipboard';
import {
getFragmentDependenciesForAST,
getOperationFacts,
VariableToType,
} from 'graphql-language-service';
import { SchemaReference } from 'codemirror-graphql/src/utils/SchemaReference';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, perhaps we should make this a top-level public export in codemirror-graphql to set a good example. @imolorhe does this make sense to you?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, codemirror-graphql currently doesn't have any top-level imports at all. Happy to follow up on this in another PR if it makes sense to you folks 🤗

@thomasheyenbrock
Copy link
Collaborator Author

what do you think of moving the DocExplorer components to @graphiql/react workspace as well?

Definitely! Will do this in a follow up to not bloat this PR too much 👍

Copy link
Member

@acao acao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is good to go, exactly the direction we need to move in!

@thomasheyenbrock thomasheyenbrock merged commit 7f695b1 into graphql:main May 13, 2022
@thomasheyenbrock thomasheyenbrock deleted the feat/graphiql-react branch May 13, 2022 09:28
@acao acao mentioned this pull request May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants