-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[gatsby-source-graphcms] Add GraphCMS Plugin #1867
Conversation
Deploy preview ready! Built with commit 7f6851c |
Deploy preview ready! Built with commit d6de985 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking fantastic!!
Excellent work!
Really love how simple the code you've come up with.
Tests would be great + a simple example site is super helpful for manual testing in the future + as a base for people to try out the plugin.
plugins: [ | ||
/* | ||
* Gatsby's data processing layer begins with “source” | ||
* plugins. Here the site sources its data from a graphql endpoint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"sources its data from the GraphCMS endpoint."
} | ||
], | ||
``` | ||
I suggest either using a `.env` file or setting environment variables to access ala `process.env.GATSBY_GRAPHQL_ENDPOINT`, `process.env.GATSBY_GRAPHQL_TOKEN` so theres no endpoint and token on git ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linking to https://www.gatsbyjs.org/docs/environment-variables/ would be better.
That page needs updated to include a reference to using process.env
for plugins.
Also you don't want to use "I" when writing docs as this is a community plugin so generally either just use command form "Use either a .env
file or set environment variables directly…" or use "We". But "we" is rarely what you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a special way to use process.env for plugins? Does the gatsby-config not have access to webpack's definitions at execution? I haven't tried it out yet, admittedly, so I will when I get home tonight.
|
||
|
||
// If type ends in a non-vowel, we need to append es. Else s. | ||
export const formatTypeName = t => `all${t}${/s$/.test(t) ? `es` : `s`}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps should use this instead? https://www.npmjs.com/package/pluralize
Or is this what GraphCMS says is their process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll use pluralize
. Forgot about all the special edge cases!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well… what does GraphCMS do? That's what matters. Unless they use pluralize as well you'll just generate a bunch of invalid queries. Can't you get directly from the available types the connection name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to @GraphCMS
[...] the process of pluralizing names is on their side. They use this library to do this: https://github.com/atteo/evo-inflector
I'll implement Looks like that's only on Java with Maven. evo-inflector
tonight.I'll implement pluralize
instead as it seems to be using the same plural rules.
Can't you get directly from the available types the connection name?
Unfortunately no, that isn't in the data returned by the __type
query. It is however returned by the __schema
query, so maybe something can be done with that...
Deploy preview failed. Built with commit 4ded842 https://app.netlify.com/sites/using-glamor/deploys/599c9aa06f4c502da66fe33b |
For some reason when using the custom query to fetch data, the nodes are not being created properly. It is missing certain fields. I haven't had the chance to test it with different data, I'll do more tests tomorrow. |
looking forward to using this ! |
what's the status on this ? |
@Thebigbignooby Been busy with work! Sorry! Trying to get this out as simply as possible, but passing the query through directly causes some issues with the createNode function. It's not populating nested data more than one or two levels deep. I'll add more context to the main post tonight. |
I have created PR #2445 since I did not know how to add to this existing one. That PR contains a working example for this plugin in examples/using-graphcms. |
Question, with the recent addition of schema stitching feature, could this be leveraged as a way to more easily plug a graphql endpoint as a data source in Gatsby ? @KyleAMathews what do you think ? |
@tlvenn: can you elaborate? |
Schema stitching is a way to stitch schema from multiple sources together into a single query: ardatan/graphql-tools#382 |
Continued in #2445 |
Adds the
gatsby-source-graphcms
plugin to fetch all data from a GraphCMS backend.Need to experiment with more complex data types and relationships to see if they're supported as is or if changes are needed.
As per @jorishermans in Discord:
TODO:
As per @mlukaszczyk from @GraphCMS, Vinylbase is the "official" demo project for GraphCMS, and they'd be delighted to have a Gatsby clone of it using the same API (https://api.graphcms.com/simple/v1/vinylbase). Spike source for reference: https://github.com/GraphCMS/example_04_static_site_generation
Issues:
1. Fields which have sub selections do not workThis one pertains to the introspection metaquery method. I'll work on that later.
Example:
The metaQuery currently used is not capable of finding
url
from the above query, which will cause the query that fetches all data to fail. It will have to be modified. It looks like it will be a bit more difficult to find thaturl
and add it to the query, as it might require making a__type
query for each field of a Type that has subfields and then modifying the final query before firing it.Errors can be seen here: https://github.com/Redmega/example_05_static_site_generation_with_gatsby
2. Embedded fields aren't found by GraphQL
Example:
This query fed into the graphcms source plugin produces artists. name, id, records, id, and titles - but no tracks, or the subfields within. They exist in the redux store json, but graphql can't seem to identify them. More investigation is needed.