in Education by
I've been trying to send a cookie back to the client from the server. I get the response data but i don't see "set-cookie" in the response headers My Apollo Server Configuration: const server = new ApolloServer({ typeDefs, resolvers, context: ({ req, connection, res }) => ({ dummyModels: dummyModels, models: models, req, connection, res, currentUser: dummyModels.users[2], dummyUsers: dummyModels.dummyUsers, }), }); app.use(cors({ credentials: true, origin: 'http://localhost:3000', // preflightContinue: true, })); My resolver: login: async (parent, args, context) => { const _include_headers = function(body, response, resolveWithFullResponse) { return {'headers': response.headers, 'data': body}; }; const loginRequestOptions = { method: 'POST', uri: 'http://localhost:3000/incorta/authservice/login', qs: { // access_token: 'xxxxx xxxxx', // -> uri + '?access_token=xxxxx%20xxxxx' user: args.input.username, pass: args.input.password, tenant: args.input.tenantName, }, transform: _include_headers, json: true // Automatically parses the JSON string in the response }; const loginResponse = await request(loginRequestOptions); console.log(loginResponse); context.res.cookie( 'JSESSIONID', tough.Cookie.parse(loginResponse.headers['set-cookie'][0]).value, { // expires : new Date(Date.now() + 9999999), // path: '/incorta/', // HttpOnly: false, // maxAge: 1000 * 60 * 60 * 24 * 99, // 99 days }, ); context.res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000'); return loginResponse.data; }, Note: i'm using request-promise-native to make the request My Apollo Client Configuration: const httpLink = createHttpLink({ uri: 'http://172.16.16.130:4000/graphql', credentials: 'include', fetchOptions: { credentials: 'include', }, }); const wsLink = new WebSocketLink({ uri: 'ws://172.16.16.130:4000/graphql', options: { reconnect: true, connectionParams: { headers: { 'x-user-header': localStorage.getItem('userObject'), }, }, } }); const terminatingLink = split( // split based on operation type ({ query }) => { const { kind, operation } = getMainDefinition(query); return kind === 'OperationDefinition' && operation === 'subscription'; }, wsLink, httpLink, ); const link = ApolloLink.from([terminatingLink]); const cache = new InMemoryCache(); export const client = new ApolloClient({ link, cache, }); I have tried tinkering with options. i don't know what i'm missing here. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can use the apollo-server-plugin-http-headers package for setting cookies in apollo server. Usage is as simple as this from within your resolvers: context.setCookies.push({ name: "cookieName", value: "cookieContent", options: { domain: "example.com", expires: new Date("2021-01-01T00:00:00"), httpOnly: true, maxAge: 3600, path: "/", sameSite: true, secure: true } });

Related questions

0 votes
    I am trying to fetch some data from the GitHub GraphQL but I get a GaphQLError. I have tried the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 19, 2022 in Education by JackTerrance
0 votes
    The apollo basic example at https://www.apollographql.com/docs/apollo-server/features/data-sources.html#Implementing- ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    We have db collection which is little complicated. Many of our keys are JSON objects where fields aren't ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 11, 2022 in Education by JackTerrance
0 votes
    I'm trying to use the mail() function on my computer so I can test the web application's system ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 30, 2022 in Education by JackTerrance
0 votes
    What kind of tasks or custom commands could be used to generate artifacts for rptproj projects during TFS ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    For some reason, when I try to install SQL Server 2008 Express, I get an error saying that I need ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    For some reason, when I try to install SQL Server 2008 Express, I get an error saying that I need ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    Why is it a good practice to separate ‘app’ and ‘server’ in Express?...
asked Jan 25, 2021 in Technology by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    I am completely new with Android/Eclipse. I can't figure out how to add an image in the /res/ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I am completely new with Android/Eclipse. I can't figure out how to add an image in the /res/ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    int n=10;int res=(n–+10>–n×5)?++n:n++ System.Out.println(res+”,”+n); what is the output Select the correct answer from above options...
asked Dec 30, 2021 in Education by JackTerrance
0 votes
    Predict the output of the following JavaScript code.
...