graphql error querying with user id

Jump to solution
julian_ebeli
Community Participant

Hi

I'm having a problem get data for a specific user from the graphql API

my graphql query is:

query MyQuery($courseID: ID!) {
  course(id: $courseID) {
    enrollmentsConnection {
      nodes {
        type
        user(id: $userID) {
          _id
          name
        }
      }
    }
  }
}
variables are:
{"courseID": redacted, "userID": redacted}

and the response is:

{
  "errors": [
    {
      "message": "Field 'user' doesn't accept argument 'id'",
      "locations": [
        {
          "line": 6,
          "column": 14
        }
      ],
      "path": [
        "query MyQuery",
        "course",
        "enrollmentsConnection",
        "nodes",
        "user",
        "id"
      ],
      "extensions": {
        "code": "argumentNotAccepted",
        "name": "user",
        "typeName": "Field",
        "argumentName": "id"
      }
    }
  ]
}

 

Are we waiting for user to be made queriable?

How do you query a user's enrolments?

Labels (1)
0 Likes
1 Solution
jerry_nguyen
Community Contributor

@julian_ebeli 

You can only use filters where they're allowed (E.g. the purple text in Canvas GraphQL explorer)

Canvas_GraphQL_UserQuery.jpg

If you want to query on a particular user, you can use "legacyNode"

E.g.

query MyQuery {
  legacyNode(_id: "9", type: User) {
    ... on User {
      id
      email
      enrollments {
        state
        type
        course {
          name
        }
      }
    }
  }
}

 

View solution in original post