Contentful - GraphQL query suddenly stopped - graphql

With no changes to my project in the slightest, my graphql no longer works
Here is the query
...
description {
content {
content {
value
}
}
description
}
...
And here was the error:
Cannot query field “content” on type “ContentfulCollectionDescription”.
I removed the issued query then checked http://localhost:8000/__graphql which is now showing:
Any idea what’s going on and how to fix?
UPDATE
I never did figure out what was going on. Instead of dealing with the issue, I created a new field, and now use that

Related

How to workaround non existent types in Graphql query in Gatsby

I'm building a website with a blog section, and on deployment to production the blog will be empty. I'm having problems allowing an empty blog on my Gatsby site.
When I run npm run develop it will only work if I have some blogs - I want it to work before the blogs have been added.
The main issues I'm encountering is trying to accomidate fields not existing like allStrapiBlog and strapiBlog because there are no blogs.
I get errors like this on blog components, and on my nav component (where i have a query that a conditional uses).
15:17 error Cannot query field "allStrapiBlog" on type "Query" graphql/template-strings
Cannot query field "strapiBlog" on type "Query"
This is what the query looks like for my navigation component. But it throws an error - is there a way to make it just return null?
query NavigationQuery {
allStrapiBlog {
nodes {
title
strapi_id
}
totalCount
}
}
How do I make unsuccessful GraphQL queries not break the build, so I can build a gatsby site with a empty blog?
But it throws an error - is there a way to make it just return null?
Indeed, you need to configure your GraphQL schema to allow nullable fields.
You have a boilerplate that you can tweak to match your data types at https://www.virtualbadge.io/blog-articles/nullable-relational-fields-strapi-gatsbyjs-graphql.
The idea relies on using the createSchemaCustomization API in your gatsbt-node.js to add your own type definitions.
Something like:
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions;
const typeDefs = `
type StrapiBlogPost implements Node {
title: String!
content: String
thumbnail: File
}
`;
createTypes(typeDefs);
};
In this case, the title is required (because of the !, which means that the type is non-nullable) while content and thumbnail can be null.
Afterward, you will only need to adapt your component to avoid code-breaking logics when null data is fetched.

shopify storefront api doesn't show filter results as expected

I'm building an app using shopify Storefront api. So far I'm able to fetch products, collections. But when I try to filter the products in a collection it is not returning results as expected. Here is what i'm trying in postman
{
collection(id:"Z2lkOi8vc2hvcGlmeS9Db2xsZWN // collection id"){
products(first:10, filters:[{productVendor:"ADDIDAS"}]){
edges{
node{
id
title
description
productType
vendor
}
}
}
}
}
But i'm getting results that have vendor of NIKE and other types. Do i need to change something?
But when i try filter using price it works fine but when i try filtering using productType it is giving me not expected results. Am i doing something wrong?
Please help here

GraphQL: No child/nested data available in response when parent is null?

I am facing problems with nullable fields when trying to use the data returned when executing my query.
Schema
A simplified schema for demonstration purpose:
type Query {
members: [Instrument!]!
}
type Instrument {
series: SeriesType!
...
}
type SeriesType {
dividendYield: SeriesMethods
...
}
type SeriesMethods{
latest: Float!
...
}
There is nullable data that is resolved at dividendYield and a typical response I get when executing the query is shown in the following section.
Typical Response
A picture of the query and response can be seen here.
So what is the problem???
We are using this data to for visuals on a web app. The data is read in as an object such that you are able to access the data by data.series.dividendYield.latest. The problem comes in when dividendYield returns null as there is there no longer exists a latest field anymore.
For the client side it will always be necessary for the field to be present in the data, even if the parent resolver is null. Is it possible for the resolvers to be setup such that all children fields also return null rather than not appearing in the data response? Any other solutions would also be appreciated.

How do I handle undefined values in Gatsby graphql?

I am using Contentful and Gatsby on my current project. I keep getting this error when I try and run my queries: TypeError: Could not find field type.
This happens on this rich text field if it is empty on Contentful's side. I do not have this issue if I add some data. This is the query fragment:
description {
childMarkdownRemark {
rawMarkdownBody
}
}
How do I handle this? Can I specify that I want this to come back as null or an empty string?

Error on GraphQL : no provided id but the store already contains an id of

I am very new to GraphQL and Apollo, and I don't understand what is wrong with the 'aliasEmail' field below. When I add this one to the query, I get this error message. When I remove it from the query, everything works perfectly.
It is well defined in 'types.graphql' and is just a simple string field.
index.js:2178 Unhandled (in react apollo:Apollo(withRouter(EmailSettingsContainer))) Error: Network
error: Error writing result to store for query:
query getCompanyForAliasEmailEditForm($companyId: ID) {
Company(id: $companyId) {
name
isTaxActive
telFixe
aliasEmail
telMobile
__typename
}
}
Store error: the application attempted to write an object with no
provided id but the store already contains an id of
Company:cje6xkcnxl83u01353a20p1t6 for this object. The selectionSet
that was trying to be written is:
Company(id: $companyId) {
name
isTaxActive
telFixe
aliasEmail
telMobile
__typename
}
It sounds like there's already another query being made elsewhere in the app that also returns the Company object and that query includes the id (or _id) field, while the query in this case does not. Apollo uses both the typename and id to generate the cache key for your query result (unless dataIdFromObject is used to modify this behavior), and so throws an error when it detects the above discrepancy. Try including the id field in your getCompanyForAliasEmailEditForm query.

Resources