-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing arguments into the resolvers by just using buildSchema
and graphql
?
#3976
Comments
The error message "Cannot read properties of undefined (reading 'name')" indicates that the name argument is undefined within your resolver.In this updated version, we are using destructuring to extract the name argument directly from the arguments object.Additionally, when constructing the GraphQL query in the source variable, we'll ensure that we're properly passing the name as a query parameter |
const requestListener = async (req, res) => {
} else { |
const http = require('http'); const schema = buildSchema( const rootValue = { const requestListener = async (req, res) => {
} else { const server = http.createServer(requestListener); server.listen(PORT, () => { |
The above is partially correct, you can also leverage variables like
At which point the request payload will look like |
How can we pass arguments into the resolvers by just using
buildSchema
andgraphql
?My code:
Result:
{"errors":[{"message":"Cannot read properties of undefined (reading 'name')","locations":[{"line":1,"column":9}],"path":["greet"]}],"data":{"greet":null}}
Result for
console.log('args =', args)
:args = undefined
Any ideas?
The text was updated successfully, but these errors were encountered: