howtographql / graphql-java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Returned null on DataFetchingEnvironment .getUser() in Mutation class

JonathanSum opened this issue · comments

AuthContext context = env.getContext(); Link newLink = new Link(url, description, context.getUser().getId());
I do not get null on context varible, but I get a null on context.getUser()

code:https://github.com/howtographql/graphql-java/blob/master/src/main/java/com/howtographql/hackernews/Mutation.java
or my code:
https://github.com/JonathanSum/myOwnJavaGraphqlStarterKit/blob/master/src/main/java/com/howtographql/hackernews/Mutation.java

I'm working on rewriting the tutorial in pure graphql-java (without graphql-java-tools), and this is what I'd recommend you try as well. the tutorial is very outdated as it is.

For the time being, your issue is very likely either because the browser doesn't send the user ID (in the Authorization header) at all or, if it does, it doesn't match the ID in Mongo.

Put a break point in createContext method in GraphQLEndpoint and inspect what happens.

The tutorial explains the code you need to add to the client to start sending the Authorization header, so make sure you followed that. otherwise, just make sure the ID it sends matches what you have in Mongo.

All right. I will wait for your next tutorial. thx for writing the new tutorial anyway.