swarthout / feathers-apollo

Feathers and Apollo Server Sample Project
MIT License
176 stars 20 forks source link

Some minor errors and other comments #4

Closed advanwinkel closed 7 years ago

advanwinkel commented 7 years ago

I found some minor errors in your code. Obviously in resolvers.js createPost should return Posts.create(args, context) instead of Users,create. In your schema the input for createPost is a postInput object. This doesn't work. Instead I provide title, content, summary and category as separate input arguments.

I think it is better to login using the standard login function of Feathers. In that case your auth.js module in services/graphql/lib is not needed. In this module you do a low level password check. Using standard Feathers login means that you only need to post username and password to the endpoint auth/local. For this I use Postman. To make this possible it is necessary to add an entry "usernameField": "username" to the auth options in config/default.json. Without this Feathers expects "email" as the field for the user name. With these modifications I built your project from scratch and uploaded it to my own github repository, https://github.com/advanwinkel/feathers-apollo-SQLite. I also made modifications in order to use SQLite as backing database, which is rather easy to achieve with Feathers.

In order to pass the web token for the mutations I post graphql queries in Postman to endpoint graphql. The web token goes into the Authorization header.

I was happy to see that you used Feathers as your framework. I think this is a very clean and elegant back end framework, which is very helpful to construct web services including authentication.

swarthout commented 7 years ago

Thanks for spotting the bug in create post. As far as the authentication goes, you are right it is cleaner and easier to use the built-in auth module, but using app.service('auth/local).create(...) does not work on the server side as of my knowledge, and I wanted to be able to log in through graphql and not use a different method.

advanwinkel commented 7 years ago

It is possible to authenticate in graphql using node module request-promise. I added the following code to resolvers.js: import request from 'request-promise';

const makeRequest = request.defaults({ baseUrl: 'http://localhost:3030', json: true }); Then I use this for the logIn method in RootMutation: logIn(root, {username, password}, context){ return makeRequest({ uri: '/auth/local', method: 'POST', body: { username: username, password: password } }); },
This way I can login from GraphQL. Do remember to put "usernameField": "username" in config/default.json, else Feathers expects "email"as username field.

swarthout commented 7 years ago

I like that a lot. Will update