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

Support for default value on fields #789

Open
mmahalwy opened this issue Feb 16, 2023 · 1 comment
Open

Support for default value on fields #789

mmahalwy opened this issue Feb 16, 2023 · 1 comment

Comments

@mmahalwy
Copy link
Contributor

mmahalwy commented Feb 16, 2023

I dont think its part of the graphql spec, so this would be mostly a helper but would be great to have a defaultValue option on fields instead of having to write a resolver to handle.

For example:

someField: t.field({
      type: 'String',
      nullable: true,
      resolve: (parent) => parent.someField || 'default value',
    }),

can become:

someField: t.exposeString('someField', {
      nullable: true,
      defaultValue: 'default value',
    }),

It could be a plugin where we have

someField: t.exposeStringWithDefault('someField', {
      nullable: true,
      defaultValue: 'default value',
    }),
@hayes
Copy link
Owner

hayes commented Feb 16, 2023

unless this makes it into Graphql itself it probably doesn't make sense for core, but as a plugin this could be cool! I probably wouldn't have time to prioritize building it myself of a while, but definitely open to a PR (and would be more than happy to help out on figuring out how to implement it).

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