-
Notifications
You must be signed in to change notification settings - Fork 53
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
WIP Gatsby Integration #41
Comments
I think this is related to gatsbyjs/gatsby#2165, which asks about a way to mirror an existing GraphQL schema and not have to recreate the entire thing in Gatsby. |
I think you have the same problem as GraphCMS had. They also have a GraphQL API and they built a source plugin which doesn't look complicated: https://github.com/GraphCMS/gatsby-source-graphcms/tree/master/src So I think you don't have to duplicate the PHP logic but instead just use your API, build gatsby nodes and gatsby will handle the rest. But I don't know if it is really so simple :) |
Thanks for the thoughts @zauni, I'm giving this a try now, but I'm wondering… if I call |
In the gatsby docs for the "Node Interface" it says Gatsby automatically infers the structure of your site’s nodes and creates a GraphQL schema which you can then query from your site’s components. (https://www.gatsbyjs.org/docs/node-interface/#graphql) How is it going? Did you get something to work? Hopefully you get something working, this would be perfect to use CraftCMS as a backend for static sites. |
I'm still working on this and think the biggest issue is that Gatsby assumes your source API stinks and abstracts it completely away. E.g., If we had a JSON API out of Craft that only returned a list of "elements" then the Gatsby API would be a huge step up. However, we actually have a fantastic API out of Craft, already. We have full text searching, per-custom-field searching, image sizing, date formatting, etc… For example, the left is what Gatsby provides and the right is CraftQL, We can beef up the Gatsby side by exposing all the text fields out to native Gatsby fields, that would gain us a bit, but it'd never be comparable to the native Craft API. I'm still investigating what can be done here. |
Hey! Sorry for jumping in here a bit late. A bit of exciting news, with gatsby v2 we're going to launch support for schema stitching! Which will mean you can reuse the native graphql API directly.
Lol :-) I wouldn't put it quite that bluntly but yeah, the assumption was that you were pulling data from a rest API w/o many options so we'd easily do better than that. Craft seems like it has an awesome API so we wouldn't want to get in the way of that. Also gatsby was meant to fulfill use cases where you just dump in raw data e.g. markdown or csv or yaml files on disk so we had to provide something on top. |
Oh one other thing. You can set node types to anything you like so you're definitely not limited there. |
Oooo! Schema stitching sounds perfect. Is this on a branch yet for testing?
Yup, that’s makes sense.
Hrm, I don’t think I’m following. I see how to make new object types/nodes. But I’m not sure I see how a field on a Node can return anything other than a string. This question may be moot with schema stitching though. |
Just pulling in some related references. Schema stitching support in a future Gatsby release should make a CraftQL implementation very feasible. Until then I'm going to put this on hold because we have some Craft-based-PHP logic that can't be smartly ported over to a |
Hello, Have you made any more progress with this? Super keen to have a play with gatsby integrated with craftcms. cheers |
No progress yet @magicspon. There's been a number of conversations around schema-stitching with Gatsby and GraphQL such as: gatsbyjs/gatsby#4708. |
https://github.com/gusnips/gatsby-source-craftcms |
This is exciting @gusnips! I gave this a try and it seemed to work as I would expect. If I'm following correctly this takes all the data out of Craft at build time and makes it available through the usual Gatsby Note for those reading through the thread: I'm still tracking schema stitching as another approach to integrating CraftQL in to Gatsby. |
Exactly, it was the only way I could get it working Thanks!! Glad I could help |
This will be of interest to those looking at integrating with Gatsby gatsbyjs/rfcs#6 |
I think this can be closed now.... 'gatsby-source-graphql' works like a charm.
then in gatsby: {
craft {
entries(section: [blog]) {
__typename
... on Craft_Blog {
title
subtitle
body {
content
}
tags {
id
title
}
}
}
}
} "lovely stuff" |
@magicspon, not sure if you're interested but in Gatsby 2 there is native schema stitching. That means you can query CraftQL directly from your React components now. No more need for a middle step of writing out the queries to a static source that you can then query. I'm planning to write up a demo of this shortly to better illustrate the amazing possibilities. Notes for future reference: |
hey @markhuot , thanks for the heads up. I've been using gatsby-source-graphql with craft/craftql and it's been pretty seamless, how does this differ? ta |
I think @magicspon already meant the native schema stitching with the official gatsby-source-graphql plugin. The old gatsby-source-graphql plugin from @wyze used graphql files for the queries. |
Yup.. I've been using the official one. |
I had the original package which I then donated to Gatsby. Sorry for the confusion! |
Is anyone having issues with gatsby-source-graphql / CraftQL in say... the past couple days? My set up was working great but now I'm getting errors and I'm unable to query. From the Gatsby GraphiQL I'm trying:
which is returning
I'm using basically the same setup as @magicspon above, but the section is named pages instead of blog. Things were working well until the past few days where I've hit this issue. Having trouble debugging it. Any help would be greatly appreciated! |
@pstinnett @markhuot Yes -- I have a demo app for something interesting coming for Gatsby which uses a query much like that. I've just tried it on Craft 3.1.19 as updated today, and can't build. I broke things down so I could run Gatsby Graphiql only, and the query then fails in a quite related way to yours. The same query in CraftQL/general GraphQL form, without the Gatsby prefixes, still runs fine, on Craftiql where that ordinary form is expected. When the Gatsby query fails, it asks me if I didn't mean any in a list of 'basic' Craft objects. This list doesn't include the sections and so forth of items I've added to make the Craft data model for the application. I thus strongly suspect the problem is coming in Schema capture, so that Gatsby GraphQL isn't able to learn about data types added to base Craft. This should be a pretty good hint to @markhuot Mark, especially if he's done something with Schema queries or Schema formats in answering them. We've in fact already spotted trouble in this area, as for weeks at least Gatsby hasn't been able to find any of Mark's directives which go beyond the very basic. His In #231 I posted a schema discovery query which finds his I ran this just now on the failing Gatsby iql. Results are too long to post here, but it sees my sections as CraftQL_SectionsEnum and CraftQL_EntryTypesEnum. and that's all. I don't see composite definitions of the Entries objects for these sections, and I find only Craft-standard fields like title, uri, etc.. -- there is no item for an This looks very much like the missing directive in the earlier case, and I think the tools are there for Mark to see what's not coming through to Gatsby. I just ran the same schema discovery query on the same Craft using its local Craftiql, and got back lots of objects related to my sections and fields, just as you would expect, so there's some definite proof these just aren't getting through, very possibly by a format failing to match, would seem one likely cause. As well, just heard from a friend who's having the same kinds of problems. Wishing us eager fortune, |
@markhuot, Mark, for your morning, I attach a report of things I've tried and possible portion of conclusion. Matt Stein, @mattstein has also been easter egging this as we chatted. Steps taken, often with some degree of short binary search on versions, and reckoning from the fact that CraftQL was working ok here, apart from the mentioned & seemingly could be related
Mark, could mention that here this is holding up a Beta with interested customer looking over a participant's shoulder, of something I think you'll be interested in as it becomes more public. Best, Clive |
@narration-sd Thanks for confirming all of that! @markhuot Should I break this off into a separate issue? Happy to provide any assistance that I can to help get this figured out. |
@pstinnett You're welcome, and I have more....a long morning of digging holes got part of an answer.
Thus on last point, anyone knowing a way to force an npm update or install to a specific date would be a hero here.... I'm thinking about ways to get the difference in good and failing schema queries out of CraftQL, not an easy one either. A break now, maybe will give a thought. Because we really need this back to working. The p.s. to this is that underlying apollo code in the schemas area is machine written, and a nightmare. Thus to just effectively back version out, the thing.... |
@narration-sd Excellent work! I agree I now do not think this is a CraftQL issue. I spent most of the day away from this issue, but just searching now I've found this in the Gatsby repo: gatsbyjs/gatsby#12717 Looks like a similar (the same?) problem... |
@narration-sd 1 more update for tonight. I do believe that issue linked above is what we're seeing. I set my gatsby version to 2.1.39 and ensured I was running gatsby develop using the project version (not global gatsby-cli) as @markhuot Sorry for the spam! Thanks for all your hard work on this plugin. |
@pstinnett no spam problem; this the good kind -- and great find. Thank you kindly for passing it on. While those Deutschland fellows eat up their evening, or next morning, I'm going to try your back-off to see if it gets us on the air right away here. |
Ok, think I have this very nicely in place for us, thanks to you @pstinnett and an add from @mattstein.
This looks to do both, plus a freebie:
@markhuot, I think you are officially off the hook :) |
...the Gatsby (cli) team fix via 2.2.7 does appear to clear yesterday's difficulties - I tested on 2.2.8, and am leaving our repo package.json devDependencies line in, modified to ^2.2.8, to catch older usage, and to prepare for any further oncoming trains like this :) |
CraftQL exposes the Craft content model through GraphQL. To do this we transform every content type/section/entry type in to a unique Object Type within GraphQL. To re-implement this in Gatsby would require re-defining the entire CraftQL schema in to a
gatsby-node.js
plugin, essentially duplicating the logic to turn Craft in to GraphQL.Personally, I was hoping that Gatsby could query CraftQL directly, but that doesn't seem to be the case.
One example: exposes an event entry type, and all the custom fields on an event. You can then find any reverse relationships to the event such as the city the event is in, the hotels related to the event, etc… CraftQL exposes this, like so:
Short of re-implementing the current PHP logic of CraftQL into a Javascript-backed
gatsby-node.js
plugin I'm not sure how to expose this level of fidelity through to a Gatsby-backed React component?Fair warning: I could be way over thinking this or approaching this from the wrong point of view. If so, sorry!
The text was updated successfully, but these errors were encountered: