feathers-apollo
feathers-apollo copied to clipboard
Feathers Auk update
Hi, I was wondering if you could please update the example to work with the latest version of FeathersJS and maybe add a frontend built on top of this starter kit, that would be super helpful.
Thanks in advance for your help
Yeah I can do that. I'm currently studying for finals at university, but in a week I'll have time to work on it. In the mean time, I always review pull requests and I would appreciate some suggestions and an update on what has changed in the new release. Thanks!
Hey that sounds good, in the meantime you can have a look at this resource.
Good luck with your finals
Started working on these updates. Can you please review my changes as I go and make sure I'm on the right track? Would appreciate it. The PR is #19
Hi Scott, sure I'll have a look during this week. Thanks again for sharing your knowledge
bump
I appreciate your persistence. I played around with this last week and I'm getting closer to getting this all upgraded. If you have progress please commit to the auk-upgrade branch. Also if you are interested in helping maintain this project let me know.
Actually I made this code with Auk version of feathers. it does not require changes... provided your feathers auk version is working (auth etc.)
if this is the case, then just do the following:
- create a folder
graphql
- create the following files
-
graphql.schema.js
-
graphql.resolvers.js
-
graphql.service.js
-
- as before add in `src/services/index.js as the last service:
- app.configure(graphql);
The code of your schema and resolvers do not change.
// Resolver example
users(root, args, context) {
return Users
.find(context)
.then(results => results.data);
},
The graphql.service.js should be looking like:
// Initializes the `graphql` service on path `/graphql`
const graphql = require('graphql-server-express').graphqlExpress;
const graphiql = require('graphql-server-express').graphiqlExpress;
const makeExecutableSchema = require('graphql-tools').makeExecutableSchema;
// const addMockFunctionsToSchema = require('graphql-tools').addMockFunctionsToSchema;
const Resolvers = require('./graphql.resolvers');
const Schema = require('./graphql.schema');
module.exports = function () {
const app = this;
// const paginate = app.get('paginate');
const executableSchema = makeExecutableSchema({
typeDefs: Schema,
resolvers: Resolvers.call(app)
});
// const options = {
// name: 'graphql',
// paginate
// };
// Initialize our service with any options it requires
app.use('/graphql', graphql((req) => {
const {token, provider} = req.feathers;
return {
schema: executableSchema,
context: {
token,
provider
}
};
}));
app.use('/graphiql', graphiql({
endpointURL: '/graphql',
}));
};
the "magic" here is to retrieve the token and add it to the context variable, thus if your authentication hooks are set on the services you resolve the requests will not go through and return an error. Thus you do not need the viewer service as from the token you can "populate" the user from the db.
That is awesome! Can you submit a PR? There is some work I started on a feature branch that you could take a look at for auth.
Hello, joining this issue.
I'm trying to update the example with latest AWK but I'm new to the subject and I get pain :)
@idealley I see no more usage of apollo package on your example, is it intentional ? Can I continue use it ? What's the advantages ? Any guidelines ?
Disapointing thing too is about you said No need to update schema and resolvers
and at the end you talk about "magic" where it is said we no more need viewer service. But in schema and resolver files, we use the viewer multiple times. So finally there is changes to these files ?
I'm trying to do it myself and get back to here if it's done.
Thanks.
Hello,
You can check this example: https://github.com/EuropeanRespiratorySociety/api-ers
Actually graphql-express-server
uses Apollo server as a dependency.
The graphql service is based on what I have written above.
Let me know if you need help.
Sam
Thanks a lot @idealley !
I have all the required materials to achieve what I am doing now.
Exploring this.