benawad / type-graphql-series

Typescript GraphQL Server built with TypeGraphQL
326 stars 129 forks source link

Error: Schema must contain uniquely named types but contains multiple types named, but i didnt defined two schemas with the same name #19

Closed joao-ortiz closed 4 years ago

joao-ortiz commented 4 years ago

this is the type that is triggering the error

const { GraphQLObjectType, GraphQLInt } = graphql;

module.exports = new GraphQLObjectType({
  name: 'Responsavel',
  fields: () => ({
    id: {
      type: GraphQLInt,
      resolve(responsavel) {
        return responsavel.id
      }
    }
  })
})

the error happens when i try to define the 'responsavel' field in the Usuario schema, i had created other fields that call other graphql schema types using the same logic, but just the 'responsavel' fires an error

const { GraphQLObjectType, GraphQLString, GraphQLInt } = graphql;
const TipoUsuarioEnumType = require('../scalar_types/TipoUsuarioEnum')
const AlunoType = require('./Aluno')
const ProfessorType = require('./Professor')
const ResponsavelType = require('./Responsavel')
const GestorType = require('./Gestor')
const AtividadeType = require('./Atividade')
const Usuario = require("../models/Usuario")
module.exports = new GraphQLObjectType({
  name: 'Usuario',
  fields: () => ({
    id: {
      type: GraphQLInt,
      resolve(usuario) {
        return usuario.id
      }
    },
    nomeDeUsuario: {
      type: GraphQLString,
      resolve(usuario) {
        return usuario.nomeDeUsuario
      }
    },
    nomeCompleto: {
      type: GraphQLString,
      resolve(usuario) {
        return usuario.nomeCompleto
      }
    },
    tipo: {
      type: TipoUsuarioEnumType,
      resolve(usuario) {
        return usuario.tipo
      }
    },
    email: {
      type: GraphQLString,
      resolve(usuario) {
        return usuario.email
      }
    },
    senha: {
      type: GraphQLString,
      resolve(usuario) {
        return usuario.senha
      }
    },
    responsavel: {
      type: ResponsavelType,
      resolve(parent, args, context, info) {
          return Usuario.findByPk(parent.id).then(usuario => {
            return usuario.getResponsavel()
          })
      }
    },
    aluno:{
      type: AlunoType,
      resolve(parent, args, context, info) {
          return Usuario.findByPk(parent.id).then(usuario => {
            return usuario.getAluno()
          })
      }
    },
    professor:{
      type: ProfessorType,
      resolve(parent, args, context, info) {
          return Usuario.findByPk(parent.id).then(usuario => {
            return usuario.getProfessor()
          })
      }
    },
    gestor: {
      type: GestorType,
      resolve(parent, args, context, info) {
          return Usuario.findByPk(parent.id).then(usuario => {
            return usuario.getGestor()
          })
      }
    },
    atividades: {
      type: AtividadeType,
      resolve(parent, args, context, info) {
          return Usuario.findByPk(parent.id).then(usuario => {
            return usuario.getAtividades()
          })
      }
    },
  })
})
benawad commented 4 years ago

is that type graphql?

joao-ortiz commented 4 years ago

i think it is, would I be able to query a non graphql type?

benawad commented 4 years ago

I formatted the code and looks like it's from the graphql package and not type-graphql

would I be able to query a non graphql type?

If you want to query something, you'll need to make it a graphql type.