-
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-contentful] Problem with JSON contentTypes #2490
Comments
So something like this:
next to this: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-contentful/src/normalize.js#L293 Consumers of this data would then have to use JSON.parse to actually use it as object. Perhaps there is better way.. |
hmmm strange, this code here is supposed to fix this problem
|
That only fixes fields named "id":
My problem seems to be that Contentful entry contains JSON field that contains fields that have number as a name. |
@TomiTakussaari I had a proposition similar to yours but instead of forcing JSON entries to be strings I added a "json" property to the object containing the whole object as string. |
Isn't this solved by PR #2967 ? |
Tha problem happens when you have JSON with numbers as keys or anything that does not pass I can see few options to solve this.
I'll be happy to create a Proposal issue as this might be a breaking change depends on the option. @KyleAMathews @MarcCoet @TomiTakussaari @sarahatwork |
For me, making JSON field only available as a string makes most sense. Having "JSON queryable" option would mean that if option is enabled, its possible to break site deploy by just adding wrong kind of JSON to any JSON field in Contentful space. Also I can't even think of a use case where I would like have my JSON field data queryable when using Contentful, I feel like its not proper way to use Contentful. |
I am also for keeping just the text content of the JSON. |
Yeah, that would simplify things if people only could query the JSON string which they |
Alright. I see. JSON as string is perfect for me too. I only use it like that anyway. |
ok cool I am a bit under the weather these days, once I am feeling better i will create a PR, should be in the next week. |
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! |
Apparently this still hasn't been implemented... Surely this must be easy to work around with the new schema customization API but I get a node validation error that won't go away. I tried a few things similar to: exports.createSchemaCustomization = ({ actions, schema }) => {
const { createTypes } = actions
const typeDefs = [
`
type contentfulBlablaJsonNode implements Node @dontInfer {
id: ID!
}
`,
]
createTypes(typeDefs)
} I guess validation happens before the |
Because the keys of nested JSON fields (e.g. `tags`, `custom_fields`, `colors`) can vary from one object to the next, this can cause brittleness for users who are interfacing with the Contentful API using GraphQL. This is because GraphQL requires users to be explicit about what fields they want to return, rather than being able to query an object for all fields regardless of what they are. To help with this, some users have suggested [1](https://github.com/gatsbyjs/gatsby/issues/2490)[2](https://forums.fauna.com/t/how-to-store-arbitrary-json-object-via-graphql/142/3) stringifying nested JSON fields and then parsing it clientside. This better ensures that queries won't break even if the returning data's underlying shape somehow breaks. Now each of the following fields will be returned as a string: - tags - custom_fields - colors.dominant_colors
Because the keys of nested JSON fields (e.g. `tags`, `custom_fields`, `colors`) can vary from one object to the next, this can cause brittleness for users who are interfacing with the Contentful API using GraphQL. This is because GraphQL requires users to be explicit about what fields they want to return, rather than being able to query an object for all fields regardless of what they are. To help with this, some users have suggested [[1](gatsbyjs/gatsby#2490)] [[2](https://forums.fauna.com/t/how-to-store-arbitrary-json-object-via-graphql/142/3)] stringifying nested JSON fields and then parsing it clientside. This better ensures that queries won't break even if the returning data's underlying shape somehow breaks. Now each of the following fields will be returned as a string: - tags - custom_fields - colors.dominant_colors
Because the keys of nested JSON fields (e.g. `tags`, `custom_fields`, `colors`) can vary from one object to the next, this can cause brittleness for users who are interfacing with the Contentful API using GraphQL. This is because GraphQL requires users to be explicit about what fields they want to return, rather than being able to query an object for all fields regardless of what they are. To help with this, some users have suggested [[1](gatsbyjs/gatsby#2490)] [[2](https://forums.fauna.com/t/how-to-store-arbitrary-json-object-via-graphql/142/3)] stringifying nested JSON fields and then parsing it clientside. This better ensures that queries won't break even if the returning data's underlying shape somehow breaks. Now each of the following fields will be returned as a string: - tags - custom_fields - colors.dominant_colors
Because the keys of nested JSON fields (e.g. `tags`, `custom_fields`, `colors`) can vary from one object to the next, this can cause brittleness for users who are interfacing with the Contentful API using GraphQL. This is because GraphQL requires users to be explicit about what fields they want to return, rather than being able to query an object for all fields regardless of what they are. To help with this, some users have suggested [[1](gatsbyjs/gatsby#2490)] [[2](https://forums.fauna.com/t/how-to-store-arbitrary-json-object-via-graphql/142/3)] stringifying nested JSON fields and then parsing it clientside. This better ensures that queries won't break even if the returning data's underlying shape somehow breaks. Now each of the following fields will be returned as a string: - tags - custom_fields - colors.dominant_colors
Because the keys of nested JSON fields (e.g. `tags`, `custom_fields`, `colors`) can vary from one object to the next, this can cause brittleness for users who are interfacing with the Contentful API using GraphQL. This is because GraphQL requires users to be explicit about what fields they want to return, rather than being able to query an object for all fields regardless of what they are. To help with this, some users have suggested [[1](gatsbyjs/gatsby#2490)] [[2](https://forums.fauna.com/t/how-to-store-arbitrary-json-object-via-graphql/142/3)] stringifying nested JSON fields and then parsing it clientside. This better ensures that queries won't break even if the returning data's underlying shape somehow breaks. Now each of the following fields will be returned as a string: - tags - custom_fields - colors.dominant_colors
Because the keys of nested JSON fields (e.g. `tags`, `custom_fields`, `colors`) can vary from one object to the next, this can cause brittleness for users who are interfacing with the Contentful API using GraphQL. This is because GraphQL requires users to be explicit about what fields they want to return, rather than being able to query an object for all fields regardless of what they are. To help with this, some users have suggested [[1](gatsbyjs/gatsby#2490)] [[2](https://forums.fauna.com/t/how-to-store-arbitrary-json-object-via-graphql/142/3)] stringifying nested JSON fields and then parsing it clientside. This better ensures that queries won't break even if the returning data's underlying shape somehow breaks. Now each of the following fields will be returned as a string: - tags - custom_fields - colors.dominant_colors
Because the keys of nested JSON fields (e.g. `tags`, `custom_fields`, `colors`) can vary from one object to the next, this can cause brittleness for users who are interfacing with the Contentful API using GraphQL. This is because GraphQL requires users to be explicit about what fields they want to return, rather than being able to query an object for all fields regardless of what they are. To help with this, some users have suggested [[1](gatsbyjs/gatsby#2490)] [[2](https://forums.fauna.com/t/how-to-store-arbitrary-json-object-via-graphql/142/3)] stringifying nested JSON fields and then parsing it clientside. This better ensures that queries won't break even if the returning data's underlying shape somehow breaks. Now each of the following fields will be returned as a string: - tags - custom_fields - colors.dominant_colors
So I tried Contentful plugin with our space, and this happens:
Our contentful space contains contentType that has Swagger api-docs in JSON fields, and Swagger api-docs has fields that are named like "200", or "400", which apparently cause this problem. (Confirmed by disabling JSON field from response)
I am not that familiar with Gatsby's GraphQL layer, or contentful plugin, but it seems that it tries to make JSON field part of the GraphQL schema (?), and numbers are obviously invalid field names there.
Should it just use JSON fields as plain strings instead ?
The text was updated successfully, but these errors were encountered: