Hey guys, I want to create a resolver that returns...
# prisma-whats-new
o
Hey guys, I want to create a resolver that returns information about the logged in user. An endpoint similar to the
/me
endpoint as seen in many APIs. As per Graphcool's online examples, issuing a query from a resolver to the CRUD Api for the logged in user would look something like this:
Copy code
const query = `
    query me($id: ID!) {
      viewer {
        User(id: $id) {
          < fields from the client go here >
        }
      }
    }
  `;
  const variables = {
    id: event.context.auth.nodeId,
  };
  const api = fromEvent(event).api('relay/v1');
  const response = await api.request(
    query,
    variables,
  );
My question is: Is there a more idiomatic way to do this in Graphcool? And would it make sense for the client to pass up a variable (potentially named
fragment
) that will be used inside the query to fetch the fields the client is interested in?
e
i’m v interested in this too, let me know what you discover!
btw are you using one of the auth templates (like username/pw or auth0 etc)?
p
I’m using Auth0, and so when I need this information I actually query their API (
/userInfo
) instead of Graphcool’s
o
I'm using the Facebook template
After some further investigating, it seems this may not be possible; at least not in a scalable way. Graphcool doesn't currently support referencing models from`types.graphql` inside a resolver's
.graphql
file. So, in attempting to create something like
me.graphql
, one would have to define a
MePayload
, which would need to be identical to the
type User @model { ... }
from the
types.graphql
file, and furthermore, the types of any nested relations on
User
would also have to be re-declared inside of
me.graphql
n
please subscribe to this feature request: https://github.com/graphcool/framework/issues/743
o
Thanks @nilan