I am using serverless framework to deploy a graphql nodejs package to lambda function.
My current serverless.yml file involves with a POST method for all communication and also another one for playground which looks like below.
functions:
graphql:
handler: handler.server
events:
- http:
path: /
method: post
cors: true
playground:
handler: handler.playground
events:
- http:
path: /
method: get
cors: true
And my handler.ts looks like this.
const { GraphQLServerLambda } = require("graphql-yoga");
const {documentSubmissionMutation} = require('./mutations/documentMutation');
const {signUpMutation, whatever} = require('./mutations/signUpMutation');
const typeDefs = `
type Query {
hello(name: String): String!
},
type Mutation {
signUp(
email: String!
password: String!
): String
sendDocuments(
user_id: String!
documents: String!
): String!
}
`
const resolvers = {
Query : {
hello : whatever
},
Mutation: {
sendDocuments: documentSubmissionMutation,
signUp: signUpMutation,
}
}
const lambda = new GraphQLServerLambda({
typeDefs,
resolvers
});
exports.server = lambda.graphqlHandler;
exports.playground = lambda.playgroundHandler;
What I would like to do now is have 3 different paths.
1 for secure and 1 for public and 1 for admin.
So basically the URL would be something like.
localhost/public localhost/secre localhost/admin
The secure path will use aws cognito pool to identify the API user api and and the other one would be open. The admin will use another aws cognito admin pool.
So first what I did was add it like this for a secure one.
const lambda = new GraphQLServerLambda({
typeDefs,
resolvers,
context: req => ({ ...req })
});
const lambdaSecure = new GraphQLServerLambda({
typeDefsSecure,
resolversSecure,
context: req => ({ ...req })
});
exports.server = lambda.graphqlHandler;
exports.playground = lambda.playgroundHandler;
exports.serverSecure = lambdaSecure.graphqlHandler;
exports.playgroundSecure = lambdaSecure.playgroundHandler;
Then in my serverless.yml file tried to put it like this.
functions:
graphql:
handler: handler.server
events:
- http:
path: /
method: post
cors: true
graphql:
handler: handler.serverSecure
events:
- http:
path: /
method: post
cors: true
playground:
handler: handler.playground
events:
- http:
path: /
method: get
cors: true
playground:
handler: handler.playgroundSecure
events:
- http:
path: /
method: get
cors: true
It din't work and threw an error
duplicated mapping key in "/Users/nihit/Desktop/serverless/cvtre/serverless.yml" at line 50, column -135:
graphql:
I tried it in different ways but I am not really sure which one is the right way to get two different URL paths.