1
resposta

Erro Cannot read property 'some' of undefined

Referente a aula '02 Organizando o schema' da seção '2 Como o GraphQL funciona'

Eu estou recebendo mensagem de erro ao tentar executar o projeto, com o typeDefs sendo importado do arquivo 'user.graphql' como mostrado na aula. Se estiver tudo no mesmo arquivo não da erro.

Seguem abaixo o log e os meus arquivos.

C:\dev\source-code\alura-graphql\graphql-config-inicial\node_modules\apollo-server-core\dist\utils\isDirectiveDefined.js:12
        return typeDef.definitions.some(definition => definition.kind === language_1.Kind.DIRECTIVE_DEFINITION &&
                                   ^

TypeError: Cannot read property 'some' of undefined
    at C:\dev\source-code\alura-graphql\graphql-config-inicial\node_modules\apollo-server-core\dist\utils\isDirectiveDefined.js:12:36
    at Array.some (<anonymous>)
    at Object.exports.isDirectiveDefined (C:\dev\source-code\alura-graphql\graphql-config-inicial\node_modules\apollo-server-core\dist\utils\isDirectiveDefined.js:8:21)
    at ApolloServer.initSchema (C:\dev\source-code\alura-graphql\graphql-config-inicial\node_modules\apollo-server-core\dist\ApolloServer.js:230:39)
    at new ApolloServerBase (C:\dev\source-code\alura-graphql\graphql-config-inicial\node_modules\apollo-server-core\dist\ApolloServer.js:159:30)
    at new ApolloServer (C:\dev\source-code\alura-graphql\graphql-config-inicial\node_modules\apollo-server-express\dist\ApolloServer.js:60:9)
    at new ApolloServer (C:\dev\source-code\alura-graphql\graphql-config-inicial\node_modules\apollo-server\dist\index.js:32:9)
    at Object.<anonymous> (C:\dev\source-code\alura-graphql\graphql-config-inicial\api\index.js:20:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)

user.graphql

const {gql} = require('apollo-server')

const userSchema = gql`
    type User {
        name: String!
        active: Boolean!
        email: String
    }
`

module.export = userSchema

index.js

const {ApolloServer} = require('apollo-server');

const userSchema = require('./user/schema/user.graphql')

const users = [
    {
        name: "Ana",
        active: true
    },
    {
        name: "Joana",
        active: false
    }
]

const typeDefs = [userSchema]

const resolvers = {}

const server = new ApolloServer({typeDefs, resolvers})

dependências package.json

"apollo-server": "^2.19.1",
    "graphql": "^15.4.0",
    "json-server": "^0.16.1",
    "nodemon": "^2.0.4"
1 resposta

Na última linha do seu arquivo user.graphql está module.export quando deveria ser module.exports (faltou o s)

Creio que seja isso.