cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
julian_ebeli
Community Participant

graphql error querying with user id

Jump to solution

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)
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
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

2 Replies
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

julian_ebeli
Community Participant

Thanks Jerry. You've taught me a heap about the graphql interface.