lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

Using query variable as a parameter in a nested field

Open newtoniumx3 opened this issue 4 years ago • 3 comments

I'm trying to use a variable passed as a parameter for a nested field. I can't figure out if its lighthouse not properly parsing this or if I'm using the wrong format. Is this supposed to work? I inspected the parsed query from the server and it seems I'm getting no value for my varaible $page

import { gql } from "@apollo/client";

export const MY_QUERY = gql`
  query MY_QUERY($group: String!, $page: Int!) {
    myGroups(input: {group: $group, page: $page}) {
      
      groups {
        styleA(page: $page) {
          name
        }
      }

    }
  }
`;


const {loading: Loading, data : Data, error: Error } = useQuery(MY_QUERY, {
  variables: {
    group: group,
    page: page
  }
});

newtoniumx3 avatar Apr 19 '21 19:04 newtoniumx3

You can use the following channels to ask support questions:

This repository and the issue tracker are used to advance the development of Lighthouse. Issues that are neither detailed bug reports nor well thought-out feature proposals will be closed.

spawnia avatar Apr 19 '21 19:04 spawnia

I feel this could be a bug? I inspected the parsed graphql selectionSet from the incoming request and that value for $page is not set on the styleA field

However if I hardcode a value, I do see it. At the same time I can access the $page variable at the root level so I confirmed that variable is definitely set when the request is sent. I'm not sure if this is a problem in the graphql library on the client or a problem on the server side parsing the request.

newtoniumx3 avatar Apr 19 '21 23:04 newtoniumx3

Alright, please provide a pull request with a failing test case then.

spawnia avatar Apr 20 '21 07:04 spawnia