forked from ParabolInc/parabol
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(11139): Team.agendaItems returns null for non-nullable field #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arthurgousset
wants to merge
8
commits into
master
Choose a base branch
from
workback/investigation/11139
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c286824
docs(workback.md): adds parabol instructions
arthurgousset bd016af
docs(workback.md): add graphql context
arthurgousset 10fdecf
test: attempt to reproduce
arthurgousset 41d7be1
style(test): linting
arthurgousset 934a7ff
test(agenda items resolver): successfully reproduces bug
arthurgousset 0d6b7c6
test(agenda items): delete incorrect tests
arthurgousset 113e1cd
fix(graphql/types/Team.ts): fix return type when not team member
arthurgousset d0865a8
fix(graphql/types/Team.ts): revert extra changes that are not related…
arthurgousset File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,39 @@ | ||
| - Always use `pnpm` to install dependencies and run scripts | ||
| - Use the Node.js version defined in package.json file under "engines". Check the version with `node -v` and change it with `nvm use` if needed. | ||
| - ALWAYS use `pnpm` run scripts | ||
| - You can assume that the server is running and the database is up at `localhost:5050` and running at `localhost:3000` | ||
| - Here are the steps I ran to start the development environment, you can use them as a reference: | ||
|
|
||
| ```bash | ||
| nvm use 22.14 | ||
| cp .env.example .env | ||
| pnpm i | ||
| # Start docker manually | ||
| pnpm db:start | ||
| pnpm relay:build | ||
| pnpn dev | ||
| ``` | ||
|
|
||
| We gave ourselves super user permissions to play around in http://localhost:3000/admin/graphql with this script: | ||
|
|
||
| ``` | ||
| pnpm node ./scripts/toolbox/assignSURole.js --add you@example.com | ||
| ``` | ||
|
|
||
| You can run GraphQL mutations in `localhost:3000/admin/graphql`: | ||
|
|
||
| ```graphql | ||
| mutation upgradetoEnterprise { | ||
| draftEnterpriseInvoice( | ||
| orgId: "XXXXX", | ||
| quantity: <number>, | ||
| email: "exampeuser@email.com", | ||
| apEmail: "invoice@email.com", | ||
| plan: "stripe_api_price_id") { | ||
| organization { | ||
| tier | ||
| } | ||
| error { | ||
| message | ||
| } | ||
| } | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import Team from '../graphql/types/Team' | ||
| import {isTeamMember} from '../utils/authorization' | ||
|
|
||
| // Mock the authorization module | ||
| jest.mock('../utils/authorization', () => ({ | ||
| isTeamMember: jest.fn() | ||
| })) | ||
|
|
||
| describe('Team.agendaItems resolver', () => { | ||
| // Extract the agendaItems resolver from the Team type | ||
| const agendaItemsResolver = Team.getFields().agendaItems?.resolve | ||
| if (!agendaItemsResolver) { | ||
| throw new Error('agendaItems resolver is not defined') | ||
| } | ||
|
|
||
| test('should return null for non-team members, causing GraphQL error', async () => { | ||
| // Set up mocks | ||
| const teamId = 'team123' | ||
| const mockTeam = {id: teamId} | ||
| const mockAuthToken = {sub: 'user123', tms: ['otherTeam123']} | ||
| const mockDataLoader = { | ||
| get: jest.fn().mockReturnValue({ | ||
| load: jest.fn().mockResolvedValue([]) | ||
| }) | ||
| } | ||
| const mockContext = {authToken: mockAuthToken, dataLoader: mockDataLoader} | ||
|
|
||
| // Mock the authorization check to simulate a non-team member | ||
| const mockedIsTeamMember = isTeamMember as jest.Mock | ||
| mockedIsTeamMember.mockReturnValue(false) | ||
|
|
||
| // Call the resolver | ||
| const result = await agendaItemsResolver(mockTeam, {}, mockContext, {} as any) | ||
|
|
||
| // Verify the resolver returns null for non-team members | ||
| expect(result).toBeNull() | ||
| expect(isTeamMember).toHaveBeenCalledWith(mockAuthToken, teamId) | ||
|
|
||
| console.log(` | ||
| TEST CONFIRMS BUG: Team.agendaItems resolver returns null for non-team members. | ||
|
|
||
| This causes the GraphQL error: "Cannot return null for non-nullable field Team.agendaItems" | ||
| because the field is defined as non-nullable in the schema: | ||
|
|
||
| type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(AgendaItem))) | ||
|
|
||
| FIX: Change the resolver implementation from: | ||
| if (!isTeamMember(authToken, teamId)) return null | ||
|
|
||
| To: | ||
| if (!isTeamMember(authToken, teamId)) return [] | ||
| `) | ||
| }) | ||
|
|
||
| test('should return an empty array for non-team members after fix', async () => { | ||
| // Set up mocks | ||
| const teamId = 'team123' | ||
| const mockTeam = {id: teamId} | ||
| const mockAuthToken = {sub: 'user123', tms: ['otherTeam123']} | ||
| const mockDataLoader = { | ||
| get: jest.fn().mockReturnValue({ | ||
| load: jest.fn().mockResolvedValue([]) | ||
| }) | ||
| } | ||
| const mockContext = {authToken: mockAuthToken, dataLoader: mockDataLoader} | ||
|
|
||
| // Mock the authorization check to simulate a non-team member | ||
| const mockedIsTeamMember = isTeamMember as jest.Mock | ||
| mockedIsTeamMember.mockReturnValue(false) | ||
|
|
||
| // Call the resolver | ||
| const result = await agendaItemsResolver(mockTeam, {}, mockContext, {} as any) | ||
|
|
||
| // IMPORTANT: This test will fail until you fix the resolver! | ||
| // After the fix, it should return an empty array instead of null | ||
| expect(Array.isArray(result)).toBe(true) | ||
| expect(result).toEqual([]) | ||
|
|
||
| console.log(` | ||
| After the fix, this test should pass, confirming that the resolver now returns | ||
| an empty array for non-team members, which satisfies the GraphQL schema requirements. | ||
| `) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the right call. While it fixes the symptom, it would be good to know why the client is requesting
agendaItemsfor non-teammembers as it probably points to a (slightly) broader issueUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, good point @Dschoordsch. For simplicity, I'll consider that a new (broader) issue #5 and consider this (smaller) issue reproduced. Should we land a fix for the symptom in the mean time? If so, I can clean this up and contribute the small fix in the mean time.
@priyankc will run WorkBack with your feedback and check if it can reproduce the bug #5 more upstream to find a broader issue. We'll open a separate PR for that to keep things clean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if we look for the real fix first. If we just make this error case not an error anymore, we will just hide the potential logic issue.
The backtrace shows it's happening during accepting a team invitation. So I think the user in question might in fact be a team member, but the subscription is evaluated before the auth token of that user was updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great feedback and thanks for the pointers. @priyankc will take ownership of this issue from here 👍