Sunday 29 December 2019

GraphQL convert Strings to Floats in args

Currently, I'm taking geolocation coordinates from my GET url parameters, which actually them into strings. i.e.

For a url like this: www.example.com?geolocation=-23.12345&geolocation=12.12345

it converts it into: ["-23.12345", "12.12345"]

Is it possible to just send it as an array of strings, which GraphQL can then reformat before testing it?

Here's a bit of my GraphQL code:

const geolocation =
    graphql.GraphQLNonNull(
        graphql.GraphQLList(
            graphql.GraphQLNonNull(
                graphql.GraphQLFloat
            )
        )
    )

var query =
    new graphql.GraphQLObjectType({
        name: "Query",
        fields:
        {
            findMaps:
            {
                args:
                {
                    geolocation:
                    {
                        type:
                            geolocation,
                    },
                },
                type:
                    convertToManyType(
                        map,
                        "map"
                    ),
                async resolve (
                    _,
                    args,
                    req
                )
                {
                    const results =
                        await findMaps(args)

                    return results
                }
            }
        }
    })


from GraphQL convert Strings to Floats in args

No comments:

Post a Comment