I'm trying to mock my graphql server, so that when I query, it returns back mock data instead of going to the graphql server. At the moment when I run my query against the mock graphql, I'm getting back this error:
"errors":[{"message":"Syntax Error GraphQL request (1:13) Expected $, found Name
\"input\"\n\n1: query login(input: {userName: \"james\" , passWord: \"password\"}
Here's my current setup:
Query
let query = `query login(input: {userName: "james" , passWord: "password"}){
login(input: {userName: "james" , passWord: "password"})
}`;
Schema
const typeDefs = `
type loginCrendentialsType {
data: String
}
input loginInputType{
userName: String!
passWord: String!
}
type RootQuery {
login(input: loginInputType): [loginCrendentialsType]
}
schema {
query: RootQuery
}
`;
Mock
const mocks = {
login: (loginInputType) => ({
data: mockDB.getUser(loginInputType.userName, loginInputType.passWord)
})
};
setup
const schema = makeExecutableSchema({
typeDefs
});
addMockFunctionsToSchema({
schema,
mocks,
});
graphql(schema,query).then((result) => {
console.log("reachedhere " + JSON.stringify(result));
});
I think when you provide input variables, it must be mutation not query??
use the variable to store the input object and assign it the $input
let query = `query login($input: {input: {userName: "james" , passWord: "password"} }){
login(input: $input)
}`;
OR
let query = `query login{
login(input: {userName: "james" , passWord: "password"})
}`;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With