Hi all
Please guide how to resolve data with nested type
query {
article {
content
author {
name
}
}
}
const express = require('express')
const fs = require('fs')
const graphQLHTTP = require('express-graphql')
const { buildSchema } = require('graphql')
const app = express()
const schema = buildSchema(`
type Article {
content: String
author: Author
}
type Author {
name: String
}
type Query {
article: Article
}
`)
const resolver = {
article() {
// data in database is kept with ID as primary key, so how to get the next function to be executed to get related data
return { content: 'Hello World', authorId: 1 }
},
author() {
// this function never get executed, please guide how
return { name: 'Steve' }
}
}
app.use(graphQLHTTP({
schema,
rootValue: resolver,
graphiql: true
}))
app.listen(3000)
Thanks
Same problem faced. Any methods solve this ?
Generate a class based return to solve this problem.
check here, or official doc
See...This
var schema=buildSchema(`
type Query{
user:User
}
type User{
Name:String
Password:String
}
`);
var resolver={
user(){
return{
Name()
{
return 'What u want to return';
},
Password()
{
return 'What u want to return';
}
}
}
}
@jeud I think @Jack-Kingdom answered your question fully. Can I close this issue?
Most helpful comment
Generate a class based return to solve this problem.
check here, or official doc