I've created a graphql server using graphql-yoga
and using volatile
as the database for my application.
So far posting works good, i'm facing issues trying to get the data i've added to the database.
Here is my code so you can help me figuring out what i'm doing wrong.
In my schema I have the next.
type Query{
memes:[Meme!]!
meme(id:ID): Meme
text:String!
}
the memes
query is the one failing.
The query itself is the next.
Query:{
memes:()=>fetch(`${VOLATILE_URL}`).then(res=>console.log(res.json())),
meme:(parent,args)=>memes.find(meme=>meme.id===args.id),
}
And this is the way I'm adding the data.
let idCount = 0;
const memes = [];
type Mutation{
createMeme(url:String!, text:String!):Meme
}
Mutation:{
createMeme:(parent,args)=>{
const meme = {
id:`${idCount++}`,
url:args.url,
text:args.text,
}
memes.push(meme);
fetch(`${VOLATILE_URL}&val={"memes_list":${memes}}`)
.then(res=>console.log(res));
//fetch(`${VOLATILE_URL}${meme.id}&val={"id":${meme.id},"url":${meme.url},"text":${meme.text}}`)
// .then(res=> console.log(res));
},
}
Now when accessing https://volatile.wtf/?key=memes
the response is my object with an array of objects.
But doing the request this way.
query{
memes{
id
url
text
}
}
I get Cannot return null for non-nullable field Query.memes
.
I'm new to graphql so I really don't know what is the way to fetch this data.
Thanks in advance.