Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda