Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
cant fetch graphql server

hi I followed a tutorial for GraphQL, that is the code I wrote until now :

    const express = require('express');
const {graphqlHTTP} = require('express-graphql');
const graphql = require('graphql')
const {
    GraphQLSchema,
    GraphQLObjectType,
    GraphQLString,
    GraphQLList,
} = graphql;
const users = require('./users.json')
const app = express();

const userType = new GraphQLObjectType({
    name:'User',
    fields: () => ({
        email: { type: GraphQLString},
        username: { type: GraphQLString},
        name: { type: GraphQLString},
        company: { type: GraphQLString},
        address: { type: GraphQLString},
    })
})

const RootQuery = new GraphQLObjectType({
    name:'RootQueryType',
    fields: () => ({
        getAllUsers: {
            type: new GraphQLList(userType),
            resolve(parent,args){
                return users
            }
        }
    })
})

const Mutation = new GraphQLObjectType({
    name:"mutation",
    fields: () => ({
        createUser: {
            type: userType,
            args:{
                email: { type: GraphQLString},
                username: { type: GraphQLString},
                name: { type: GraphQLString},
                company: { type: GraphQLString},
                address: { type: GraphQLString},
            },
            resolve(parent,args){
                users.push({ email: args.email,
                             username: args.usename,
                             name: args.name,
                             company: args.company,
                             adress: args,company,
                })
                return args
            }
        }
    })
})

const schema = new GraphQLSchema({query: RootQuery, mutation: Mutation})

app.use('/graphql', graphqlHTTP({
    schema:schema,
    graphql:true
}))
app.listen(5000, ()=>{
    console.log('server started')
})

but when I got to localhost:5000/graphql in the browser I get : {"errors":[{"message":"Must provide query string."}]} i tried to check graphqlstring is imported correctly and everything is fine I searched a lot, I hope the answer is here.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Can you replace graphql: true, by graphiql: true, ? as per here Also in general try to have the port as 4000

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda