i am in a phase of converting from another headless cms.to payloadjs.
i would need to convert the below to payloadjs, but i could find how to do fragments nor a way to define the SearchInput type.
can you please give me some directions on how to start implementing this on payloadjs:
export const searchResultFragment = `
fragment SearchResult on SearchResult {
productId
productName
description
slug
sku
currencyCode
productAsset {
id
preview
}
priceWithTax {
... on SinglePrice {
value
}
... on PriceRange {
min
max
}
}
}
`
export const searchQuery = `
query search($input: SearchInput!) {
search(input: $input) {
docs {
...SearchResult
}
totalDocs
}
}
${searchResultFragment}
`
For writing/converting your GraphQL queries you can mess around in the graphql playground!
https://payloadcms.com/docs/graphql/overview#graphql-playgroundIf you're running locally it'd be at
localhost:<your port/3000>/api/graphql-playground
. That's where I write all of my queries first. It has really nice self documentation and schema generation
thanks i use this cool tool. still i can't find on the documentations how to define a custom type for graphql (the SearchInput variable ).
Payload will generate the types automatically based on your schema. So if you have a field called
searchInput
it will generate the schema you need to access it automatically
cool your suggestion works like a magic. and what about the fragments? do you support this as well?
for example, i would need to query with the 3 dots to spread the fragment:
...SearchResult
I do this sort of thing all the time! Fragments, inline fragments... Payload implements a fully functional GraphQL API, so you can do anything you can normally with GraphQL (and more!)
You can even have relationship fields that will automatically expand and give you the fields from that related document
ok cool i will try that, thanks
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.