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

Custom argument inputs #31

Open
baohouse opened this issue Nov 23, 2019 · 1 comment
Open

Custom argument inputs #31

baohouse opened this issue Nov 23, 2019 · 1 comment

Comments

@baohouse
Copy link

baohouse commented Nov 23, 2019

Due to my company's deadline being fairly short, I had to fork graphiql-explorer in order to implement custom argument input and check it into our codebase. I'd prefer to stick with the official plugin instead maintaining it internally.

One of the problem with using GraphQL enums is that you don't necessarily get a human-readable enum. Or we have fields that are String, but we want to have them select from a list. So it would look something like this (assetTypes):

I do this by exposing a getScalarArgInput prop, and pass in a function that feels similar to getDefaultScalarArgValue.

export function getScalarArgInput(parentField, arg, argType, argValue, onChange, styleConfig) {
  const unwrappedType = unwrapOutputType(parentField.type);
  if (
    unwrappedType.name === 'AccountBalance' &&
    arg.name === 'assetTypes' &&
    argType.name === 'String'
  ) {
    return (
      <select
        onChange={onChange}
        style={{ color: styleConfig.colors.builtin }}
        value={argValue ? argValue.value : undefined}
      >
        {_.map(FinancialAssetType, ({ code, description }) => (
          <option key={code} value={code}>
            {description}
          </option>
        ))}
      </select>
    );
  }
  return;
}

Wondering if this would be useful to check in.

@FluorescentHallucinogen
Copy link
Contributor

PTAL at #47. 😉

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

No branches or pull requests

2 participants