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/plugin-code-exporter #2758

Merged
merged 19 commits into from
Oct 28, 2022

Conversation

LekoArts
Copy link
Contributor

@LekoArts LekoArts commented Sep 7, 2022

Description

Adds https://github.com/OneGraph/graphiql-code-exporter, copying what #2715 did.
Only "problems" are:

  • The library itself is pretty outdated, maybe one should consider vendoring it completely?
  • The underlying UI doesn't use the new @graphiql/react components
  • a11y issues

With a bunch of CSS overrides it works fine now.

Preview

Bildschirmaufnahme.2022-09-08.um.13.35.50.mov

Related Issues

Doing that to unblock myself for gatsbyjs/gatsby#36541

@changeset-bot
Copy link

changeset-bot bot commented Sep 7, 2022

🦋 Changeset detected

Latest commit: 56e56f1

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

This PR includes changesets to release 2 packages
Name Type
graphiql Patch
@graphiql/plugin-code-exporter Minor

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

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Sep 7, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@acao
Copy link
Member

acao commented Sep 7, 2022

@LekoArts this is looking great, thank you! also, hello and nice to see you again, welcome!

i think all you need to do is to use @graphiql/react to generate the props you need for graphiql-code-exporter, similarly to how the graphiql explorer plugin works

@LekoArts
Copy link
Contributor Author

LekoArts commented Sep 8, 2022

Hey 👋 Nice to see you again, too 😊

I think I wired up all the props correctly, maybe @thomasheyenbrock sees an issue. But right now I'm trying to debug the code exporter itself as it somehow fails there:

image

@LekoArts
Copy link
Contributor Author

LekoArts commented Sep 8, 2022

Styling is way off but setting the props directly in the user code for now unblocked me

image

@LekoArts
Copy link
Contributor Author

LekoArts commented Sep 8, 2022

Current state of things:

Bildschirmaufnahme.2022-09-08.um.13.35.50.mov

@LekoArts LekoArts marked this pull request as ready for review September 8, 2022 11:55
@LekoArts
Copy link
Contributor Author

LekoArts commented Sep 8, 2022

Which icon set do y'all use and which icon should this plugin get?

@thomasheyenbrock
Copy link
Collaborator

Hey @LekoArts, this is awesome! You caught me heading out on vacation until end of next week, so I won't be able to give this a proper review until then.

Which icon set do y'all use and which icon should this plugin get?

I'm actually not sure if the icons GraphiQL uses for docs and history were custom-made by @julianbauer (who created the new design) or if they are coming from any library. For the explorer plugin I just picked a random one that I found online that kinda matched the others.

@LekoArts
Copy link
Contributor Author

LekoArts commented Sep 8, 2022

Ok, good to know. Enjoy your vacation!

Then I'll pick an icon (with proper license) to my best judgement :D

@LekoArts LekoArts mentioned this pull request Sep 8, 2022
2 tasks
@LekoArts
Copy link
Contributor Author

LekoArts commented Sep 9, 2022

Added the arrow-up-on-square from https://heroicons.com/

image

@LekoArts
Copy link
Contributor Author

@thomasheyenbrock I'll be on vacation next week, are you back? From my side everything would be finished

@thomasheyenbrock
Copy link
Collaborator

Hey @LekoArts 👋 I'm back since this week. I'll have time tomorrow to give this a review, but it already looks amazing! 😍

LekoArts and others added 2 commits October 1, 2022 09:40
Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com>
Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com>
@LekoArts
Copy link
Contributor Author

LekoArts commented Oct 4, 2022

@thomasheyenbrock Anything I can help with to get this reviewed?

@LekoArts
Copy link
Contributor Author

@thomasheyenbrock @acao ICYMI

@thomasheyenbrock
Copy link
Collaborator

@LekoArts sorry that this has been stuck for a while and it's my fault, I dropped the ball on this one. I currently only have time one day every other week to really focus on GraphiQL, so Friday this will be my first thing to review 🤞

Copy link
Collaborator

@thomasheyenbrock thomasheyenbrock left a comment

Choose a reason for hiding this comment

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

Awesome work 👏 just some minor stuff, but apart from these this is looking good!

@@ -0,0 +1 @@
// / <reference types="vite/client" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

We had an issue with out eslint config which always broke triple-slash directives (should by fixed by now)

Suggested change
// / <reference types="vite/client" />
/// <reference types="vite/client" />

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not fixed for me :/

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's also like that in the other packages so I don't think this was fixed

Comment on lines 41 to 48
export type GraphiQLCodeExporterProps = {
query: string;
snippets: Array<Snippet>;
codeMirrorTheme: string;
variables?: string;
context?: Record<string, any>;
schema?: GraphQLSchema | null | undefined;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

These are different to the prop definitions that I find in the source repository:

  • codeMirrorTheme is optional in the source repo but required here
  • variables and context are required in the source repo but optional here
  • A bunch of other props from the source repo are just missing here
    Are there particular reasons for deviating from the prop definitions? Could we try to mirror them here instead of just declaring a subset?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

codeMirrorTheme is optional in the source repo but required here

With the ref handling for some reason the default props weren't applied. So unless (with the current code) you define the codeMirrorTheme explicitly, the whole thing didn't work.

Maybe when I'll remove the wrapper it works, I'll test it.

variables and context are required in the source repo but optional here

But they are set with {} defaults. So actually their types are incorrect and they are optional.

A bunch of other props from the source repo are just missing here

I didn't find them useful at the time, as I just wanted to make something minimal working. But I can copy the types, yeah.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also the props differ from README to code 😆
https://github.com/OneGraph/graphiql-code-exporter#props

packages/graphiql-plugin-code-exporter/src/index.css Outdated Show resolved Hide resolved
packages/graphiql-plugin-code-exporter/src/index.tsx Outdated Show resolved Hide resolved
packages/graphiql-plugin-code-exporter/package.json Outdated Show resolved Hide resolved
packages/graphiql-plugin-code-exporter/vite.config.ts Outdated Show resolved Hide resolved
yarn.lock Outdated Show resolved Hide resolved
yarn.lock Outdated Show resolved Hide resolved
packages/graphiql-plugin-code-exporter/README.md Outdated Show resolved Hide resolved
@LekoArts
Copy link
Contributor Author

Thanks for the comments! I'll adjust the PR shortly :)

@thomasheyenbrock
Copy link
Collaborator

Some more UI feedback after checking out the branch locally (screenshots and GIFs attached):

  • The headline and the deprecated close button need some attention (you can solve that similarly to how the explorer-plugin does it)
  • The plugin content has a fixed width and doesn't scale with the plugin pane
  • The styles for the dropdown menus could still be improved (check out the execute button for reference)

CleanShot 2022-10-14 at 10 56 53@2x


CleanShot 2022-10-14 at 10 59 10


CleanShot 2022-10-14 at 11 00 51

LekoArts and others added 2 commits October 14, 2022 11:16
- deduplication
- vite bundle config
- move package to devDep
- remove wrapper react component
- eslint thingy
Co-authored-by: Thomas Heyenbrock <thomas.heyenbrock@gmail.com>
@LekoArts
Copy link
Contributor Author

@thomasheyenbrock

The headline and the deprecated close button need some attention (you can solve that similarly to how the explorer-plugin does it)

Where is that close button coming from and how I can enable it for testing?

@LekoArts
Copy link
Contributor Author

Bildschirmaufnahme.2022-10-14.um.12.59.10.mov

For me the pane hasn't a fixed width (on Chrome and Firefox). I set it to width: calc(100% - 2 * var(--px-16))

@LekoArts
Copy link
Contributor Author

Fixed the dropdown styles

Bildschirmaufnahme.2022-10-14.um.13.18.39.mov

@LekoArts
Copy link
Contributor Author

FYI, for now I copied the code from here to gatsbyjs/gatsby#36541 and at the moment we just publish it ourselves. I'd still like to use this package once published instead of maintaining our own version :)

@thomasheyenbrock
Copy link
Collaborator

Where is that close button coming from and how I can enable it for testing?

I think that didn't happen for you because you also used the explorer plugin at the same time. Without the stylesheet from that plugin the styles are missing. I just did some finishing touches here and already added that part.

Copy link
Collaborator

@thomasheyenbrock thomasheyenbrock left a comment

Choose a reason for hiding this comment

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

Thanks for this awesome plugin and your patience @LekoArts 🙇 gonna merge and publish this today!

@thomasheyenbrock
Copy link
Collaborator

thomasheyenbrock commented Oct 28, 2022

...if CI doesn't act up. Seems like unpkg has some issues 🤷 Loading https://unpkg.com/react-dom@17/umd/react-dom.development.js consistently returns a 520

@thomasheyenbrock
Copy link
Collaborator

Works again! CI is happy ✅

@thomasheyenbrock thomasheyenbrock merged commit d63801f into graphql:main Oct 28, 2022
@acao acao mentioned this pull request Oct 28, 2022
@thomasheyenbrock
Copy link
Collaborator

This is released now as @graphiql/plugin-code-exporter@0.1.0!

@LekoArts
Copy link
Contributor Author

LekoArts commented Nov 2, 2022

Thanks @thomasheyenbrock 👍 I'll then update our internal usage to this plugin instead :)

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.

None yet

4 participants