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

Feature/plugin custom graphql scalars #47

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

TimLehner
Copy link
Contributor

This is an expansion of the ideas in PR #46

@FluorescentHallucinogen
Copy link
Contributor

@TimLehner 👍 BTW, have you seen #10 (comment)? It would be really nice to have plug-ins for input fields that are object types with child fields, not only scalars (leafs). Is this possible with this PR?

@FluorescentHallucinogen
Copy link
Contributor

Also found #31.

Copy link
Contributor

@FluorescentHallucinogen FluorescentHallucinogen left a comment

Choose a reason for hiding this comment

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

See https://www.npmjs.com/package/graphql-iso-date for more info about the difference between Date and DateTime custom GraphQL scalars. 😉

const customISODateTypeHandler = {
render: (arg, styleConfig, onChangeHandler) => (
<input
type="date"
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it should be "datetime-local" instead of "date", because you use .toISOString().

}}
/>
),
canProcess: (arg) => arg && arg.type && arg.type.name === 'Date',
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it should be "DateTime" instead of "Date", because you use .toISOString().

import * as React from 'react';

function canProcess(arg) {
return arg && arg.type && arg.type.name === 'Date';
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it should be "DateTime" instead of "Date", because you use .toISOString().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The DateInput is distinct from the example in the README which demonstrates adding additional handlers not bundled with the explorer.

This bundled plugin is just a direct implementation of the Date input in the POC PR.

function render(arg, styleConfig, onChangeHandler) {
return (
<input
type="date"
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it should be "datetime-local" instead of "date", because you use .toISOString().

@TimLehner
Copy link
Contributor Author

@FluorescentHallucinogen
I have added support for more complex types, the plugins need to return some React.Element-like object. I've added an example implementation of a plugin for a Complex Number type in the README

@FluorescentHallucinogen
Copy link
Contributor

@sgrove @dwwoelfel Please review this pull request.

@dwwoelfel dwwoelfel self-requested a review April 15, 2020 17:06
Copy link
Collaborator

@dwwoelfel dwwoelfel 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 great!

@TimLehner can you move everything into the Explorer.js file.

We're trying to keep a single file because some people copy Explorer.js and drop it into their code base for development or because they want to make small customizations for their environment.

@TimLehner
Copy link
Contributor Author

I can, but I wonder if it would be better to provide that sort of functionality using typescript compiler options?

I could look at some tsconfig to make the output dist/ a single file? Feels better to me to generate that then force the code structure one way

@baohouse
Copy link

baohouse commented Apr 22, 2020

@TimLehner can you move everything into the Explorer.js file.
We're trying to keep a single file because some people copy Explorer.js and drop it into their code base for development or because they want to make small customizations for their environment.

I don't mind dropping a folder in if it means the code is split up according to the classes used. It makes updating easier when we can preserve original code in files that don't need customization.

…into feature/plugin-custom-graphql-scalars
@TimLehner
Copy link
Contributor Author

This is great!

@TimLehner can you move everything into the Explorer.js file.

We're trying to keep a single file because some people copy Explorer.js and drop it into their code base for development or because they want to make small customizations for their environment.

Have moved everything into Explorer.js as requested. I will look into making a new PR to split Explorer.js up into the individual classes responsible, and typescript-ify my contributions.

The goal is to be able to provide the best of both worlds:

  • A structured project to allow easier contributions from multiple people, minimising merge conflicts
  • A method of building a single Explorer.js file, still in ES2016 or similar, for users who wish to drag-and-drop this single file into their implementation and make small tweaks
  • The existing ./dist, which packages the minified .js in commonjs

This will be a separate PR, so I think this can now be closed and merged if there are no further comments -- would it be nice if the plugins are based on an abstract base class so it is clear for third-parties how to implement their own plugins?

@TimLehner TimLehner mentioned this pull request Apr 24, 2020
@FluorescentHallucinogen
Copy link
Contributor

@dwwoelfel PTAL.

@FluorescentHallucinogen
Copy link
Contributor

@sgrove @dwwoelfel Ping.

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