Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Implement support for variables in query #93

Closed
PiotrSzlagura opened this issue Jun 13, 2018 · 2 comments
Closed

Implement support for variables in query #93

PiotrSzlagura opened this issue Jun 13, 2018 · 2 comments
Assignees
Labels

Comments

@PiotrSzlagura
Copy link

PiotrSzlagura commented Jun 13, 2018

Preconditions

  1. Repository version: 2.3-develop-plus-pr13-and-pr48
  2. PHP: 7.1.18
  3. Server: nginx, version: 1.12.2

Steps to reproduce

  1. Create empty Magento instance
  2. Install sample data from repo
  3. Using graphql client/plugin of your choice (tested on many of them, always with the same result) run query:
query GetProductsQuery($page: Int, $filterInput: ProductFilterInput){
  products(
    pageSize: 10
    currentPage: $page
    filter: $filterInput
    sort: {}
  ) {
    items {
    	name
    }
  }
}

with variables:

{
  "page": 1,
  "filterInput": {
    "price": {
    	"gt": "10"
    }
  }
}

Expected result

  1. Query should return filtered products list, since ProductFilterInput is an input type, according to scheme

Actual result

  1. Received following error:
Variable "$filterInput" cannot be non-input type "ProductFilterInput".
Variable "$filterInput" of type "ProductFilterInput" used in position expecting type "ProductFilterInput".

I've tested this approach on clean GraphQL installation and it worked without any problem.

EDIT:
After hours of debugging and testing, it turned out that this isn't even implemented. Any type given is mapped as OutputType, which finally breaks the query, as output types can't be used as query parameters. I made a workaround that works for my case for now, but it would be awesome if it was included in the core. I could share my solution with you but it's rather ugly and not universal so I doubt it could be any use for you.

@misha-kotov misha-kotov changed the title Can't use input type variables in query Implement support for variables in query Jun 14, 2018
@paliarush
Copy link
Contributor

@PiotrSzlagura Feel free to share your solution via PR, then we can work on it together and eventually merge to the mainline.

@paliarush
Copy link
Contributor

Verified the issue:

  • Scalar types are supported
  • Object input types are not supported. Errors are thrown as described by @PiotrSzlagura

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants