Skip to content

Query parameters don't get converted to appropriate GraphQL typesΒ #41

@thecodeboss

Description

@thecodeboss

Description

When passing arguments in a query string, there is no type conversion step. So strings don't get converted into integers, etc. For example, an HTTP request like this one:

GET https://myapi.com/projects?limit=100

would attempt to pass the limit parameter as a string "100" instead of consulting the GraphQL schema and realizing it is supposed to take an Int type instead.

It's possible to define a middleware that converts these, however I'd like to suggest it as a feature instead. Most GraphQL built-in scalar types I think could be automatically converted, but obviously custom scalars or non-scalars would still require custom middleware to be built.

Another workaround is to use the request body instead of the query string, as JSON allows you to specify scalars without ambiguity.

I would be happy to take a stab at creating a pull request for this if there's no immediate objection to the idea.

Steps to Reproduce

Set up a graphql2rest project with the following GraphQL Schema:

type Project {
  id: ID!
}

type Query {
  projects(limit: Int): [Project!]!
}

this manifest.json:

{
  "endpoints": {
    "/projects": {
      "get": {
        "operation": "projects"
      }
    }
  }
}

and then execute this HTTP request:

GET https://myapi.com/projects?limit=100

You should get a GraphQL error like the following:

Variable "$limit" got invalid value "100"; Expected type Int. Int cannot represent non-integer value: "100"

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions