question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sending enum-arguments as variables (with Relay) mostly results in VariableTypeMismatch

See original GitHub issue

This issue is a bit related to the question and answer on http://stackoverflow.com/questions/35946313/how-to-set-a-relay-variable-as-an-enum-value/35987582#35987582, however my issue is specifically server-side.

I have these relevant parts of the schema for Users:

Users(orderBy: [UserOrdering]): UserConnection

input UserOrdering {
  sort: UserSortField!
  direction: SortDirection!
}

enum UserSortField {
  FIRSTNAME
  LASTNAME
  FULLNAME
}

enum SortDirection {
  ASC
  DESC
}

When sending the query with orderBy specified as a variable:

query($orderBy: [UserOrdering]!) {
  viewer {
    ...on LoggedInViewer {
      Users(orderBy:$orderBy) {
        edges {
          node {
            fullName
          }
        }
      }
    }
  }
}

variables:
{
  "orderBy": [{"sort": "FULLNAME", "direction": "ASC"}]
}

Most of the times I get back: Validation error of type VariableTypeMismatch: Variable type doesn't match.

When sending orderBy hardcoded, the query always works:

query {
  viewer {
    ...on LoggedInViewer {
      Users(orderBy: [{sort:FULLNAME, direction:ASC}]) {
        edges {
          node {
            fullName
          }
        }
      }
    }
  }
}

Now, the strange thing is that sometimes querying with orderBy as a variable works (when sending the query with GraphiQL a couple of times). I suspect it has something to do with the order of execution on the server-side, but I’m not sure what to look for exactly.

Can you help me making this query work consistently?

NB: I’m using version 2016-09-02T14-27-54 of graphql-java

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dminkovskycommented, Nov 17, 2016

Ahhh thank you @TomerSabags. This makes sense… so we can add VariableTypeMismatch to the list of rules that depend on == for validation (#85).

1reaction
fibberscommented, Sep 10, 2016

After debugging this a bit futher, I now see when the error is thrown.

Some debugging notes about the variables when evaluating VariableTypesMatchRule.checkVariable:

  • this results in the error:
    variableReference: VariableReference{name='orderBy'}
    variableDefinition: VariableDefinition{name='orderBy', type=NonNullType{type=ListType{type=TypeName{name='UserOrdering'}}}, defaultValue=null}
    variableType: GraphQLNonNull{wrappedType=graphql.schema.GraphQLList@259b9b2e}
      wrappedType: graphql.schema.GraphQLList@259b9b2e
        wrappedType: graphql.schema.GraphQLInputObjectType@259b9b2e
          name: “UserOrdering”
    inputType: graphql.schema.GraphQLList@37d2f318
      wrappedType: graphql.schema.GraphQLInputObjectType@37d2f318
        name: “UserOrdering”
    
  • this results in a succesful response:
    variableReference: VariableReference{name='orderBy'}
    variableDefinition: VariableDefinition{name='orderBy', type=NonNullType{type=ListType{type=TypeName{name='UserOrdering'}}}, defaultValue=null}
    variableType: GraphQLNonNull{wrappedType=graphql.schema.GraphQLList@5cb3019a}
      wrappedType: graphql.schema.GraphQLList@5cb3019a
        wrappedType: graphql.schema.GraphQLInputObjectType@5cb3019a
          name: “UserOrdering”
    inputType: graphql.schema.GraphQLList@5cb3019a
      wrappedType: graphql.schema.GraphQLInputObjectType@5cb3019a
        name: “UserOrdering”
    

Now, let’s find out why variableType.wrappedType sometimes refers to a different object than inputType (which causes VariablesTypesMatcher to error).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Variables - Relay
Relay guide to query variables. ... When sending a network request to fetch the query above, we need to provide both the query,...
Read more >
Apollo React GraphQL VariableTypeMismatch error
state object. I get the following error: [GraphQL error]: Message: Validation error of type VariableTypeMismatch: Variable type doesn't match, Location: ...
Read more >
2021年08月_weixin_39810196的博客_CSDN博客
Sending enum-arguments as variables (with Relay ) mostly results in VariableTypeMismatch. 2021-01-11. Cuckoo Web TemplateSyntaxError when checking behavioral ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found