const { ApolloServer, gql } = require('apollo-server-express'); const express = require('express'); const port = process.env.PORT || 4000; const notes = [ { id: '1', content: 'This is a note', author: 'Adam Scott' }, { id: '2', content: 'This is another note', author: 'Harlow Everly' }, { id: '3', content: 'Oh hey look, another note!', author: 'Riley Harrison' } ]; const typeDefs = gql ` type Note { id: ID content: String author: String } type Query { hello: String notes: [Note] note(id: ID!): Note } type Mutation { newNote(content: String!): Note } `; const resolvers = { Query:{ hello: () => 'Hello World', notes: () => notes, note: (parent, args) => { return notes.find(note => note.id == args.id); }, Mutation: { newNote: (parent, args) => { let noteValue = { id : String(notes.length + 1), content : args.content, author: 'Adam Scott', }; notes.push(noteValue); return noteValue; } } }, }Algunas personas tuvieron problemas con los nombres, pero parece que estoy usando lo mismo en la resolución y en el esquema. Tenga paciencia conmigo, este es mi segundo día en GraphQL y Express. Eliminé intencionalmente las importaciones y la asignación de objetos express, middleware ya que no me permite publicar.
Creo que simplemente te falta un corchete.
const resolvers = { Query:{ hello: () => 'Hello World', notes: () => notes, note: (parent, args) => { return notes.find(note => note.id == args.id); } }, <==== THIS IS MISSING =====> Mutation: { newNote: (parent, args) => { let noteValue = { id : String(notes.length + 1), content : args.content, author: 'Adam Scott', }; notes.push(noteValue); return noteValue; } }