querying with graphql on a custom query doesn't query a relationship data.
//payload.config
...
search: {
type: payload.Query.fields.Products.type,
args: {
input: {
type: new GraphQL.GraphQLInputObjectType
(
{
name: 'SearchInput',
fields: {
term: { type: GraphQL.GraphQLString },
}
)
}
},
resolve: search,
}
//search file
export default async (parent, args, context) => {
let query:any = {
collection: "products",
where: {},
...sort
}
if(args.input.term)
query.where.name = { contains: args.input.term }
const products = await context.req.payload.find(query);
for (let product of products.docs){
console.log(product) // output below
}
return products;
}
//products output:
{
id: '6458a18fceb82968a83902cd',
mainImage: {
id: '6458a18eceb82968a83902c9',
...
}
}
//query the graphql
query getAllProducts($input: SearchInput! = { term: "SE" }) {
search(input: $input) {
docs {
mainImage {
id
}
}
}
}
//results
{
"data": {
"search": {
"docs": [
{
"mainImage": null // mainImage is null
}
]
}
}
}
//model
{
name: 'mainImage',
type: 'upload',
relationTo: 'media-main',
},
Does adding
depth: 0
to your local API find() query fix it?
That was an issue that I had
yes. it solved the issue 😶
I'll make sure to document this!
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.