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

Graphql Errors for unused templates #11278

Closed
pgegenfurtner opened this issue Jan 25, 2019 · 17 comments
Closed

Graphql Errors for unused templates #11278

pgegenfurtner opened this issue Jan 25, 2019 · 17 comments
Labels
topic: GraphQL Related to Gatsby's GraphQL layer

Comments

@pgegenfurtner
Copy link
Contributor

Description

Using the new theme functionality, I have a core theme from which I generate multiple different projects, which consume this theme.
In the core theme I have different page templates. Some may not be used by theme consumers. But data which these unused templates want to query may not be available in a theme consumer, so I get a graphql error and the site cannot be build.
Is there some way around this?

@KyleAMathews
Copy link
Contributor

Sooner than later yes as themes will be able to define the schema they expect to exist. /cc @freiksenet @ChristopherBiscardi

@gatsbot
Copy link

gatsbot bot commented Feb 18, 2019

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

Thanks for being a part of the Gatsby community! 💪💜

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Feb 18, 2019
@ChristopherBiscardi
Copy link
Contributor

silly gatsbot. keep this open while we work on the data abstractions.

@DSchau DSchau added not stale and removed stale? Issue that may be closed soon due to the original author not responding any more. labels Feb 19, 2019
@pgegenfurtner
Copy link
Contributor Author

Is there a solution for this yet?

@pieh
Copy link
Contributor

pieh commented Apr 3, 2019

We released support for "schema customization" API ( https://www.gatsbyjs.org/blog/2019-03-18-releasing-new-schema-customization/ ) that allow you to define types, so schema is consistent even without having any data.

Can you provide more information what kind of sources are you using, as examples of this might be different depending on what you are using.

@pgegenfurtner
Copy link
Contributor Author

@pieh That sounds like a solution, but I don't unterstand how I would implement this.
I will try to give an example..

I have projects A and B, both using my theme. In the theme I have a query fragment for a component newsletter. The fragment looks like this:

export const newsletter = graphql`
    fragment Newsletter on DirectusProject {
        newsletter {
            endpoint
            mail
        }
    }
`;

Project A does have a newsletter configuration. Project B does not (and does not use the newsletter component). So in the graphql schema the newsletter node under directusProject is not present.
I believe what I would need is to create this node with just null values.

@pieh
Copy link
Contributor

pieh commented Apr 3, 2019

Idea is that you would use something like this:

exports.sourceNodes = ({ actions }) => {
  actions.createTypes(`
    type Newsletter {
      endpoint: String
      mail: String
    }

    type DirectusProject implements Node {
      newsletter: Newsletter
    }
  `)
}

so even if newsletter field is never used - it will be created in schema correctly and queries don't break.

Ultimately it would be ideal if Directus plugin would create those types automatically (if it knows the type structure), so users don't have to do that manually. But this is new feature and we are stillworking on it, so it will take some time for ecosystem to catch up.

@pieh pieh closed this as completed Apr 3, 2019
@pieh pieh reopened this Apr 3, 2019
@pieh
Copy link
Contributor

pieh commented Apr 3, 2019

Sorry, random click - I didn't mean to close it.

@pgegenfurtner
Copy link
Contributor Author

This solves my problem, thank you!

@lannonbr
Copy link
Contributor

lannonbr commented Apr 3, 2019

So are we good to close this issue now @pgegenfurtner ?

@pgegenfurtner
Copy link
Contributor Author

Yes

@pgegenfurtner
Copy link
Contributor Author

Sorry, I have to reopen this.

In the project where the newsletter field is present, the createTypes function seems to override it with null values. What am I doing wrong here? I implemented the function in my theme.

@pgegenfurtner pgegenfurtner reopened this Apr 3, 2019
@freiksenet
Copy link
Contributor

@pgegenfurtner Hm, that shouldn't happen. What is value that's present in the newsletter? I wonder if it'd be possible for you to share a reproduction project with us.

@freiksenet
Copy link
Contributor

Ping @pgegenfurtner

@pgegenfurtner
Copy link
Contributor Author

The value is just null.
I will try to publish a reproduction repo.
But basically I implemented this like @pieh suggested:


exports.sourceNodes = ({ actions }) => {
  actions.createTypes(`
    type Newsletter {
      endpoint: String
      mail: String
    }

    type DirectusProject implements Node {
      newsletter: Newsletter
    }
  `)
}

@freiksenet
Copy link
Contributor

@pgegenfurtner That looks like it should work. Could you also include data that's inside DirectusProject type?

@sidharthachatterjee
Copy link
Contributor

Closing this because the problem described in here is solved by defining a schema using the schema customisation API.

With respect to not warning for unused templates, let's track that in #20413

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: GraphQL Related to Gatsby's GraphQL layer
Projects
None yet
Development

No branches or pull requests

9 participants