Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"eslint-plugin-babel": "2.1.1",
"express": "4.13.3",
"express3": "*",
"express-session": "^1.11.3",
"flow-bin": "0.14.0",
"graphql": "0.4.5",
"isparta": "3.0.3",
Expand Down
38 changes: 37 additions & 1 deletion src/__tests__/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
GraphQLString
} from 'graphql';
import graphqlHTTP from '../';
import session from 'express-session';

var QueryRootType = new GraphQLObjectType({
name: 'QueryRoot',
Expand All @@ -43,7 +44,11 @@ var QueryRootType = new GraphQLObjectType({
thrower: {
type: new GraphQLNonNull(GraphQLString),
resolve: () => { throw new Error('Throws!'); }
}
},
sessionId: {
type: new GraphQLNonNull(GraphQLString),
resolve: rootValue => rootValue.session.id
},
}
});

Expand Down Expand Up @@ -1215,5 +1220,36 @@ describe('test harness', () => {
);
});
});
describe('Session available in Graphql', () => {

it('sessionId should be the same across requests', async () => {
var app = express();

app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }, saveUninitialized: true }));

app.use(urlString(), graphqlHTTP(req => ({
schema: TestSchema,
pretty: true,
rootValue: { session: req.session }
})));

var response = await request(app)
.get(urlString({
query: '{sessionId}',
}));

expect(response.status).to.equal(200);
var sessionIdFirstRequest = JSON.parse(response.text).data.sessionId;
expect(sessionIdFirstRequest).to.not.equal(null);

response = await request(app)
.get(urlString({
query: '{sessionId}',
}));

var sessionIdSecondRequest = JSON.parse(response.text).data.sessionId;
expect(sessionIdSecondRequest).to.equal(sessionIdFirstRequest);
});
});
});
});