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

[1.0] Creating Interfaces/Unions on sourcing/transforming/typegen? #885

Closed
danielfarrell opened this issue May 1, 2017 · 6 comments
Closed
Labels
type: documentation An issue or pull request for improving or updating Gatsby's documentation

Comments

@danielfarrell
Copy link
Contributor

Is there a way to add Union types of Interfaces from plugins?

@KyleAMathews KyleAMathews added the type: documentation An issue or pull request for improving or updating Gatsby's documentation label May 1, 2017
@KyleAMathews
Copy link
Contributor

So currently there's an API for extending the graphql types that Gatsby creates. You can see implementations in gatsby-typegen-remark and gatsby-typegen-sharp.

A simplified implementation looks like:

exports.extendNodeType = ({
  type,
}) => {
  if (type.name !== `TypeToModify`) {
    return {}
  }

  return {
    greeter: {
      type: GraphQLString,
      args: {
        name: {
          type: GraphQLString,
          defaultValue: "Bob",
        },
      },
      resolve(node, { name }) {
        return `Hi ${name}!`
      },
    },
  }
}

What this doesn't let you do is create entirely new types. Is that what you'd need? We could easily add a new API hook at

that'd let you mutate things however you want before the schema is created.

@danielfarrell
Copy link
Contributor Author

danielfarrell commented May 1, 2017

I think I would need to create new types for union/interface types, yeah. I could probably change things to live without them if it's not something of interest to others, but that API hook would interest me.

Should I take a stab at implementing it in a PR?

@KyleAMathews
Copy link
Contributor

Should I take a stab at implementing it in a PR?

Yes please!

New API hooks are a one liner to add.

@jbolda jbolda added the v1 label Jun 3, 2017
@KyleAMathews
Copy link
Contributor

Open PR for this @ #2990

@cvharris
Copy link

cvharris commented Apr 5, 2018

Is extendNodeType deprecated? Is the alternative recommended solution for this problem to use setFieldsOnGraphQLNodeType?

@m-allanson m-allanson removed the v1 label Apr 13, 2018
@KyleAMathews
Copy link
Contributor

Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation An issue or pull request for improving or updating Gatsby's documentation
Projects
None yet
Development

No branches or pull requests

5 participants