System Information
- Strapi Version 4.2
- MacOs
- sqlite
- Node Version:
- NPM Version:
- Yarn Version:
Hi,
I’ve created a custom resolver for my app, based on this tutorial
https://www.theitsolutions.io/blog/how-to-add-custom-graphql-query-to-strapi-v4
I try to fetch data from a .findMany() method, then agregate it, and send it back.
fetching and modify the datas works fine, but when I try graphql playground, I have a message :
"message": "Undefined binding(s) detected when compiling WHERE. Undefined column(s): [t0.id] query: where
t0.
id = ?",
Here is the full resolver
module.exports =
(strapi) =>
({ nexus }) => {
// console.log(nexus);
return {
types: [
nexus.extendType({
type: "Query", // extending Query
definition(t) {
t.field("popularity", {
// with this field
type: "PopularityResponse", // which has this custom type (defined below)
args: {
id: nexus.nonNull("ID"), // and accepts a product id as argument
startDate: nexus.nonNull("String"),
endDate: nexus.nonNull("String"),
branding: nexus.nonNull("String"),
},
resolve: async (parent, args, context) => {
// console.log(context)
return {
// and resolves to the 3rd party popularity service logic
googleid: args.id,
startDate: args.startDate,
endDate: args.endDate,
branding: args.branding,
};
},
});
},
}),
nexus.objectType({
name: "PopularityResponse", // this is our custom object type
definition(t) {
// t.nonNull.int("stars"); // with a result of the 3rd party popularity service response
t.field("myData", {
// and if requested, a field to query the product content type
// type: "ImpressionEntityResponse",
type: "ImpressionEntityResponse",
resolve: async (parent, args) => {
const query = await strapi.db
.query("api::impression.impression")
.findMany({
where: {
googleid: {
id: {
$eq: parent.googleid,
},
},
date_debut: {
$gte: parent.startDate,
},
date_fin: {
$lte: parent.endDate,
},
},
// populate: { googleid: true },
args,
});
let aggregate = query.reduce(
(acc, key) => {
// vérifie si la campagne est dans la liste
if (
[parent.branding].some((elem) => {
let reg = new RegExp(elem);
return reg.test(key.campaignName);
})
) {
let brandingIndex = acc.branding.findIndex(
(el) => el.date_debut == key.date_debut
);
if (brandingIndex !== -1) {
// si on a un élément
acc.branding[brandingIndex].search_impression_share +=
parseInt(key.search_impression_share);
} else {
acc.branding.push({
search_impression_share: parseInt(
key.search_impression_share
),
date_debut: key.date_debut,
});
}
} else {
let nobrandingIndex = acc.nobranding.findIndex(
(el) => el.date_debut == key.date_debut
);
if (nobrandingIndex !== -1) {
// si on a un élément
acc.nobranding[
nobrandingIndex
].search_impression_share += parseInt(
key.search_impression_share
);
} else {
acc.nobranding.push({
search_impression_share: parseInt(
key.search_impression_share
),
date_debut: key.date_debut,
});
}
}
return acc;
},
{ branding: [], nobranding: [] }
);
console.log(query.value);
console.log("\n\n==> agregate", aggregate);
return { value: query };
}, // but relations, components and dynamic zones of the Product will be handled by built-in resolvers
});
},
}),
],
resolversConfig: {
"Query.popularity": {
auth: {
scope: [
"api::impression.impression.findOne",
"api::impression.impression.find",
], // we give permission to use the new query for those who has findOne permission of Product content type
},
},
},
};
};
I’m searching for two days, and I can’t find any answer.
Here is my gql query
query GetPopularity {
popularity(id: "37", startDate:"2022-06-13",endDate:"2022-07-15",branding:"brand") {
myData {
data {
attributes {
googleid {
data {
attributes {
g_customer_id
}
}
}
}
}
}
}
}
When I console.log “agregate”, I get my computed datas as I want it. But within graphql playground I get the undefined bindings error, and the datas is null.
"data": {
"popularity": {
"myData": {
"data": {
"attributes": {
"googleid": null
}
}
}
}
}
If you have any suggestion, it will be of good help.
Thanks you all
Fabien