You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our CreateLink mutation left incomplete because we could not authorize users back then, so let's get back to it and complete the implementation.
979
-
With what we did in [authentication middleware](#authentication-middleware) we can retrieve user in resolvers using ctx argument. so in CreateLink function add these lines:
978
+
Our CreateLink mutation left incomplete because we could not authorize users back then, so let's get back to it and complete the implementation. With what we have now, we can check whether the user is logged in or not by checking the Authorization HTTP header.
979
+
With what we did in authentication middleware we can retrieve user in resolvers using ctx argument. so in CreateLink function add these lines:
980
980
981
981
`resolver.go`:
982
982
```go
@@ -1073,6 +1073,37 @@ func GetAll() []Link {
1073
1073
```
1074
1074
1075
1075
and Our app is finally complete.
1076
+
To test the endpoint navigate to localhost:8080 and write the mutation to create link:
if you try it now you will get a access denied message:
1087
+
```json
1088
+
{
1089
+
"errors": [
1090
+
{
1091
+
"message":"access denied",
1092
+
"path": [
1093
+
"createLink"
1094
+
]
1095
+
}
1096
+
],
1097
+
"data":null
1098
+
}
1099
+
```
1100
+
So you may realize that we prevented not logged in users from submitting links, To create link now you must set the Authorization header. From the bottom select HTTP Headers button and fill it like this:
1101
+
```js
1102
+
{
1103
+
"Authorization":""// use your own generated token
1104
+
}
1105
+
```
1106
+
Try again you should be able to create a new link now.
1076
1107
1077
1108
## Summary <a name="summary"></a>
1078
1109
Congratulations on make it to here! You've learned about gqlgen library and some Graphql fundamentals. By implementing a HackerNews clone you've learned about queries, mutations, authentication and GraphQL query language.
0 commit comments