0

I am using Hasura for GraphQL on server. I am trying to run this query

query MyQuery {
  user_attribute_values(where: {id: {_eq: 3}}) {
    id
    attribute_id
    user_id
    value
    user_attribute {
      enum_attribute_type {
        value
      }
    }
  }
}

which should return me something like this

{
  "data": {
    "user_attribute_values": [
      {
        "id": 3,
        "attribute_id": 3,
        "user_id": 2,
        "value": "true",
        "user_attribute": {
          "enum_attribute_type": {
            "value": "boolean"
          }
        }
      }
    ]
  }
}

but it's returning me

{
  value: "true"
  updated_at: "2020-04-16T07:23:04.568105+00:00"
  deleted_at: null
  created_at: "2020-04-16T07:23:04.568105+00:00"
  id: 3
  user_id: 2
  attribute_id: 3
}

So apparently it's just ignoring the inner part and just returning me one level of data.

This is the way I am trying to do it

const client = new ApolloClient({
  uri: process.env.REACT_APP_HASURA_GRAPHQL_URL,
});

<ApolloProvider client={client}>
  ... all my remaining code
</ApolloProvider>

const USER_ATTRIBUTES_QUERY = gql`
  {
    user_attribute_values(where: { id: { _eq: 3 } }) {
      id
      attribute_id
      user_id
      value
      user_attribute {
        enum_attribute_type {
          value
        }
      }
    }
  }
`;

const { loading, error, data } = useQuery(USER_ATTRIBUTES_QUERY);

It's very straight forward simple code but doesn't seem to be working.

Usman Tahir
  • 2,513
  • 4
  • 24
  • 38
  • If that's your query, then that's what your server will return. Please clarify what you're inspecting to arrive at the conclusion that the wrong data is being returned... the HTTP response from the server? The `data` variable? – Daniel Rearden Apr 19 '20 at 10:53
  • First one is query, 2nd one is what GraphiQL is returning me on adding the same query, but the 3rd one is the response which I am getting after pushing the same query using apollo – Usman Tahir Apr 19 '20 at 11:18
  • So how are you determining that's the response? Are you just doing `console.log(data)`? – Daniel Rearden Apr 19 '20 at 11:22

1 Answers1

0

It seems like your relationships may be untracked on the Hasura side? Make sure your foreign keys are in place, track your relationships, and check to make sure you have permissions set for all of those nested columns

moto
  • 946
  • 10
  • 27