I'm am using contentful to hold re-usable feature information for products. I have a content model where I have products and I have features. The products each have a reference field where you can select multiple features (which is returned as an array of strings). How do I use GraphQL to query additional information about the features that my product has? features is a reference field so I was expecting a relationship in GraphQL.


query ($category: String!, $subCategory: String!, $product: String!, $rrp: Float!, $verdictRating: Int!) {
product: allContentfulProduct(
filter: {
categories: {slug: {eq: $category}},
subCategories: {slug: {eq: $subCategory}},
slug: {eq: $product}
}) {
edges {
node {
productId
brand {
name
slug
}
name
slug
categories {
slug
}
subCategories {
slug
}
features
color
}
}
}
cc @Khaledgarbaya
馃憢
your query can be something like this
query ($category: String!, $subCategory: String!, $product: String!, $rrp: Float!, $verdictRating: Int!) {
product: allContentfulProduct(
filter: {
categories: {slug: {eq: $category}},
subCategories: {slug: {eq: $subCategory}},
slug: {eq: $product}
}) {
edges {
node {
productId
brand {
name
slug
}
name
slug
categories {
slug
}
subCategories {
slug
}
features {
...on ContentfulFeatureType {
name
etc...
}
}
color
}
}
}
the FeatureType is the type a.k.a contentype of the feature reference. You can have multiple ...on depends on how many type you are referencing
Thank you @Khaledgarbaya!
Most helpful comment
馃憢
your query can be something like this
the
FeatureTypeis the type a.k.a contentype of the feature reference. You can have multiple...ondepends on how many type you are referencing