Skip to content

Commit

Permalink
[graphql] rename context to userContext and add non-null output
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed May 1, 2020
1 parent 97b491d commit 3905997
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
Expand Up @@ -3,15 +3,15 @@ import { gql } from '../testUtils';
it('context rejects anonymous users', async () => {
const result = await gql`
{
context {
userContext {
state
}
}
`();
expect(result).toMatchInlineSnapshot(`
Object {
"data": Object {
"context": null,
"userContext": null,
},
"errors": Array [
[GraphQLError: Invalid authentication header],
Expand All @@ -23,9 +23,8 @@ it('context rejects anonymous users', async () => {
it('Returns user context', async () => {
const result = await gql`
{
context {
userContext {
state
issuedAt
data {
searchedText
}
Expand All @@ -47,11 +46,10 @@ it('Returns user context', async () => {
expect(result).toMatchInlineSnapshot(`
Object {
"data": Object {
"context": Object {
"userContext": Object {
"data": Object {
"searchedText": "Foo",
},
"issuedAt": 1586013070089,
"state": "CHOOSING_ARTICLE",
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/resolvers/Query.js
Expand Up @@ -4,7 +4,7 @@ export default {
return {};
},

context(root, args, context) {
userContext(root, args, context) {
return context.userContext;
},
};
7 changes: 3 additions & 4 deletions src/graphql/typeDefs.graphql
Expand Up @@ -4,7 +4,7 @@ type Query {
insights: MessagingAPIInsight

# Current user's chatbot context
context: UserContext @auth
userContext: UserContext @auth
}

type MessagingAPIInsight {
Expand Down Expand Up @@ -130,9 +130,8 @@ enum MessagingAPIInsightStatus {
}

type UserContext {
state: String
issuedAt: Float
data: StateData
state: String!
data: StateData!
}

type StateData {
Expand Down

0 comments on commit 3905997

Please sign in to comment.