Hey folks!
I have schema that includes Users and Groups. The relevant parts are:
type User {
id: ID!
sub: String! @id
displayName: String!
}
type Group
@auth(
query: {
or: [
{
rule: "query ($sub: String!) { queryGroup { owner(filter: { sub: {eq: $sub} }) { id } } }"
}
{ rule: "query { queryGroup(filter: { public: true } ) { id } }" }
]
}
) {
id: ID!
name: String!
slug: String! @id
public: Boolean @search
owner: User!
}
# Dgraph.Authorization { "VerificationKey": "...", "Algo": "RS256", "Header": "X-Auth-Token", "Namespace": "https://example.com/jwt/claims", "Audience": ["Auth0ClientID"], "ClosedByDefault": true }
What I’d like is for a query like:
{
queryGroup {
name
slug
public
owner {
displayName
}
}
}
to return all public groups, and if a JWT is provided, also the private groups that the current user owns.
When providing a valid JWT into the API Explorer, this works. When I don’t provide an JWT I’m told "message": "couldn't rewrite query queryGroup because a valid JWT is required but was not provided"
.
So it looks like the JWT is mandatory. What’s the best way to do this so I can have a public response to unauthenticated requests, and a response that includes the extra data when authentication passes?
Thanks in advance!
Ben