Sails: apollo-server. Include it in Sails like a middleware is not possible?

Created on 8 Aug 2018  路  11Comments  路  Source: balderdashy/sails

Sails version: 1.0.x
Node version: 8.x
NPM version: 6.x
DB adapter name: N/A
DB adapter version: N/A
Operating system: Win/Mac



I'm trying to use the guide in Readme (here: https://github.com/apollographql/apollo-server#getting-started) to use apollo-server and here: https://sailsjs.com/documentation/concepts/middleware.

I'm trying with config/http.js:

module.exports.http = {
  middleware: {
    order: [
      "cookieParser",
      "session",
      "bodyParser",
      "compress",
      "poweredBy",
      "router",
      "www",
      "favicon",
      "apolloServer"
    ],

    apolloServer: async function() {
      const express = require("express");
      const { ApolloServer, gql } = require("apollo-server-express");

      const typeDefs = gql`
        type Query {
          hello: String
        }
      `;

      const resolvers = {
        Query: {
          hello: () => "Hello world!"
        }
      };

      const apolloServ = new ApolloServer({ typeDefs, resolvers });
      const app = express();
      return apolloServ.applyMiddleware({ app });
    }
  }
};

But I know this is not good (and indeed it doesn't work).

How can I include apollo-server?

I'm not the only one:

3rd party package more info please what do you think?

Most helpful comment

Discounting Apollo and GraphQL wholesale because you think that it doesn't have authentication and authorization built in, isn't a proper answer.

https://blog.apollographql.com/authorization-in-graphql-452b1c402a9

All 11 comments

Hi @frederikhors! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]

Ok, sailsbot! :D

Sorry to be a hassle, but it looks like your issue is still missing some required info. Please double-check your initial comment and try again.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]

Try now, @sailsbot!

Sorry to be a hassle, but it looks like your issue is still missing some required info. Please double-check your initial comment and try again.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]

AI right?

Sorry to be a hassle, but it looks like your issue is still missing some required info. Please double-check your initial comment and try again.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]

@frederikhors In this case, Apollo is not middleware and it is not going to work with sails. GraphQL does a lot of the same things as the Blueprint API does for sails, but honestly I don't recommend using either for any kind of production grade app. This is because making your database secure and restricting data to only the appropriate users will create more work and problems, than using a more traditional server/database. I'm sorry that this doesn't help if you are required to use Apollo/GraphQL, but hopefully it helps you on the right path.

Discounting Apollo and GraphQL wholesale because you think that it doesn't have authentication and authorization built in, isn't a proper answer.

https://blog.apollographql.com/authorization-in-graphql-452b1c402a9

sails do not want to work around this issue ?

@frederikhors @jafar-rezaei @netik We appreciate all the feedback so far - what are some further business use case(s) for apollo-server in Sails?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

3imed-jaberi picture 3imed-jaberi  路  3Comments

svmn picture svmn  路  4Comments

G2Jose picture G2Jose  路  4Comments

anissen picture anissen  路  3Comments

kesavkolla picture kesavkolla  路  4Comments