feathers-apollo icon indicating copy to clipboard operation
feathers-apollo copied to clipboard

Feathers Auk update

Open lobosan opened this issue 7 years ago • 11 comments

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

lobosan avatar Apr 26 '17 21:04 lobosan

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!

swarthout avatar Apr 26 '17 21:04 swarthout

Hey that sounds good, in the meantime you can have a look at this resource.

Good luck with your finals

lobosan avatar Apr 27 '17 12:04 lobosan

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

swarthout avatar May 04 '17 22:05 swarthout

Hi Scott, sure I'll have a look during this week. Thanks again for sharing your knowledge

lobosan avatar May 08 '17 13:05 lobosan

bump

nacmonad avatar Jul 19 '17 05:07 nacmonad

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.

swarthout avatar Jul 19 '17 06:07 swarthout

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:

  1. create a folder graphql
  2. create the following files
    • graphql.schema.js
    • graphql.resolvers.js
    • graphql.service.js
  3. 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.

idealley avatar Sep 05 '17 12:09 idealley

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.

swarthout avatar Sep 06 '17 03:09 swarthout

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.

3kynox avatar Oct 14 '17 15:10 3kynox

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

idealley avatar Oct 14 '17 16:10 idealley

Thanks a lot @idealley !

I have all the required materials to achieve what I am doing now.

Exploring this.

3kynox avatar Oct 14 '17 19:10 3kynox