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

won't work if Craft "gqlTypePrefix" config is set. #58

Open
webrgp opened this issue Nov 24, 2021 · 9 comments
Open

won't work if Craft "gqlTypePrefix" config is set. #58

webrgp opened this issue Nov 24, 2021 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@webrgp
Copy link
Contributor

webrgp commented Nov 24, 2021

Description

If you try to set "gqlTypePrefix" to "Craft_" on a working Craft + Gatsby implementation, you get:

"gatsby-source-craft" threw an error while running the createSchemaCustomization lifecycle:

Field "id" at path "RequiredEntryFields" has no parent type. This may indicate that your remote schema had changed and
your fragment "RequiredEntryFields" must be updated.

  524 |     const schema = await getSchema();
  525 |     const gatsbyNodeTypes = await getGatsbyNodeTypes();
> 526 |     const documents = await compileNodeQueries({
      |                             ^
  527 |         schema,
  528 |         gatsbyNodeTypes,
  529 |         customFragments: await collectFragments(),

File: node_modules/gatsby-source-craft/gatsby-node.js:526:29
  • Craft version: 3.7.22
  • PHP version: 8.0
  • Database driver & version: mysql
  • Plugins & versions: just this one
@webrgp webrgp added the bug Something isn't working label Nov 24, 2021
@andris-sevcenko andris-sevcenko self-assigned this Nov 25, 2021
@andris-sevcenko
Copy link
Contributor

Interesting, I'll take a look!

@webrgp
Copy link
Contributor Author

webrgp commented Nov 29, 2021

Hi @andris-sevcenko, I would like to help with some code. I am a pretty decente js/ts developer, how can I help? Do you have a process/setup in place that you use to develop and test this plugin?

Thanks!

@andris-sevcenko
Copy link
Contributor

Ah, shoot, so sorry about forgetting this.

There's no setup, really. Just a local Gatsby install that I use and then I throw code at the wall and see what sticks!

To work around this issue I'll have to add another config setting to the source plugin to mirror the gqlTypePrefix setting that's set on Craft, otherwise, the source plugin won't be able to find anything.

I'll get to that now, so you can resume your work!

andris-sevcenko pushed a commit to craftcms/gatsby-helper that referenced this issue Nov 30, 2021
@andris-sevcenko
Copy link
Contributor

Okay, just pushed 69a00d7 to fix this and a release should follow today, too!

You will also need to update the Gatsby Helper plugin to version 1.0.9.

@andris-sevcenko
Copy link
Contributor

Also, in the future, you can just submit PRs without specifically asking permission - I don't have a "smart" build process or anything like that - just make changes, compile to JS and that's it :)

All testing currently is done via a "does it build?" test, unfortunately, as we don't have many resources dedicated to this plugin, currently,

@andris-sevcenko
Copy link
Contributor

@webrgp We'll publish a release for this tomorrow - I want to get some more stuff in the helper plugin and this plugin too, so that it's able to react better to nuances that differ between Craft versions. (see #59)

@webrgp
Copy link
Contributor Author

webrgp commented Nov 30, 2021

Just tested locally and with gatsby-starter-minimal and it works. The reason this particular issue is significant is because when writing queries in Gatsby that would work both at build and at the client (querying Craft's GraphQL API directly ) to reduce duplication.

In my specific project, I've set 'gqlTypePrefix' => 'Craft_' in Craft and typePrefix: "" in Gatsby, because I still need Craft's types and queries to be namespaces in Gatsby.

@webrgp
Copy link
Contributor Author

webrgp commented Nov 30, 2021

Spoken too early. All the assets types and interfaces lost localFile and when I consolo.log iface I get undefined at:

const iface = intermediateSchema.getType(ifaceName);

@webrgp
Copy link
Contributor Author

webrgp commented Nov 30, 2021

Sent pull request #60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants