I really just want to start at the very basic level and get the click-to-edit overlays to work first.
I have my query to fetch data set to put the site into draft mode and that is working properly to retrieve draft content when I test it out.
export default (query, options) => {
const variables = options?.variables || {};
const runtimeConfig = useRuntimeConfig();
// Create a reactive key that includes the variables
const key = computed(() => {
const vars = toValue(variables);
return JSON.stringify({
query,
variables: vars,
});
});
const result = useFetch('https://graphql.datocms.com', {
key,
method: 'POST',
headers: {
Authorization: `Bearer ${runtimeConfig.public.datoCmsToken}`,
...(runtimeConfig.public.NUXT_ENV !== 'production' && {
'X-Include-Drafts': true,
}),
},
body: computed(() => {
const vars = toValue(variables);
return {
query,
variables: vars,
};
}),
watch: [key], // Explicitly watch the key for changes
transform: ({ data, errors }) => {
if (errors) throw new errors();
return data;
},
});
return result;
};
I can see I’m supposed to add these 2 parameters to my request, but not sure where they go and it has not worked if I add them to the body. I don’t see them in the useQuery.ts composable that is part of the starter kit.
Thank you will give that a try and see what happens!
I am wondering about the query method I am using - I think I got it from an older composable DatoCMS was providing years ago. I am wondering is there an advantage to using the buildRequestInit() method from datocms/cda-client vs. just using useFetch and adding the X-Include-Drafts header?
@roger I am running my own query following the useQuery composable in my local files, but the data comes back undefined when I have the contentLink parameter in there, but if I remove it then the data fetches properly. Any idea what is going on there? Thanks for your help!