0

I am trying to retrieve data from an API using GraphQL and Express. For some reason, I am only getting null as a result. I am new to GraphQL so, I am unsure why it is not working. Am I missing a configuration?

Thank you in advance.

The API URL is: https://api.tfl.gov.uk/bikepoint

server.js

const express = require('express');
const expressGraphQL = require('express-graphql')
const schema = require('./schema/schema')

const app = express();

app.use('/graphql', expressGraphQL({
    schema,
    graphiql: true,
}))

app.listen(4000, () => {
    console.log("Listening")
});

schema.js

const graphql = require('graphql')
const axios = require('axios')

const {
    GraphQLObjectType,
    GraphQLString,
    GraphQLInt,
    GraphQLSchema
} = graphql;

const BikepointType = new GraphQLObjectType({
    name: 'Bikepoint',
    fields: {
        id: { type: GraphQLString},
        url: { type: GraphQLString},
        commonName: { type: GraphQLString},
        placeType: { type: GraphQLString}
    }
})

const RootQuery = new GraphQLObjectType({
    name: 'RootQuery',
    fields: {
        bikepoint: {
            type: BikepointType,
            args: { id: { type: GraphQLString } },
            resolve( parentValue, args ) {
                return axios.get(`https://api.tfl.gov.uk/bikepoint`)
                .then( resp => resp.data );
            }
        }
    }
});

module.exports = new GraphQLSchema({
    query: RootQuery
});
Diego Oriani
  • 1,647
  • 5
  • 22
  • 31

1 Answers1

0

I forgot to add the args.id.

Solution:

axios.get(`https://api.tfl.gov.uk/bikepoint/${args.id}`)
Diego Oriani
  • 1,647
  • 5
  • 22
  • 31