-
Notifications
You must be signed in to change notification settings - Fork 2
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
chore: Drop adminClient
(1/2)
#2356
Conversation
Removed vultr server and associated DNS entries |
c1746ca
to
353008e
Compare
353008e
to
6ed792a
Compare
🤖 Hasura Change Summary compared a subset of table metadata including permissions: Updated Tables (1)
|
@@ -1116,6 +1116,16 @@ | |||
- message | |||
- session_id | |||
- created_at | |||
select_permissions: |
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.
This was required to give the API role access to the insert_reconciliation_requests_one
mutation.
insert_<object>_one
will only be available if you have select permissions on the table, as it returns the inserted row
Docs: https://hasura.io/docs/latest/mutations/postgres/insert/#insert-a-single-object
jest.mock("@opensystemslab/planx-core", () => { | ||
const actualCoreDomainClient = jest.requireActual( | ||
"@opensystemslab/planx-core", | ||
).CoreDomainClient; | ||
|
||
return { | ||
CoreDomainClient: jest.fn().mockImplementation(() => ({ | ||
formatRawProjectTypes: () => mockFormatRawProjectTypes(), | ||
})), | ||
CoreDomainClient: class extends actualCoreDomainClient { | ||
constructor() { | ||
super(); | ||
this.formatRawProjectTypes = () => mockFormatRawProjectTypes(); | ||
} | ||
}, | ||
}; | ||
}); |
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.
What's going on here?
CoreDomainClient
client is being mocked so that we can control and modify the behaviour of formatRawProjectTypes()
and test it.
However, we want to retain the behaviour of CoreDomainClient.client
so that real GraphQL queries get made so that graphql-query-test-mock
is able to catch and mock these calls. To do this we can use jest.requireActual
to maintain this behaviour.
I feel like there's possibly a few more elegant options here - I'd like to revisit this.
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.
This structure is repeated a few times throughout this PR. I spent a good bit of time attempting to generalise it so that we could import it with an interface similar to -
function mockCoreDomainClient(customMocks = {}) {
const actualCoreDomainClient = jest.requireActual(
"@opensystemslab/planx-core",
).CoreDomainClient;
return {
CoreDomainClient: class extends actualCoreDomainClient {
constructor() {
super();
Object.assign(this, customMocks)
}
}
}
}
...
mockCoreDomainClient({
formatRawProjectTypes: () => mockFormatRawProjectTypes(),
});
Tried a few variations without much success - I suspect the problem is related to how Jest is hoisting mocks (through the jest.mock("@opensystemslab/planx-core")
notation). I wanted to just move on as opposed to losing more time here so I'll open a GitHub issue describing this.
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.
Issue logged here - #2404
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.
Thanks for following through with all these updates and thorough explanations of how you've set up mocks here!
Left a few naming suggestions for clarity, but overall looks good 👍
* feat: Analytics * feat: Session summary * feat: Publish * feat: Move flow * feat: Find and replace * feat: getFlowData() * feat: insertFlow() * feat: getMostRecentPublishedFlow() * chore: Drop unused function * feat: Payment status * feat: Payment requests * feat: Operations * chore: Drop adminGraphQLClient * chore: Linting * fix: PR comments
What does this PR do?
api
role in Hasura #2294adminClient
(still in "god mode" using the Hasura admin secret)$public
or$api
clientsPrinciples
Queries should be typed (by default
planx-core
is returning anunknown
otherwise). For simplicity I've just used the mutation / query name as the interface name. If this isn't clear / meaningful I can append aQuery
/Mutation
suffix.Where possible, use queries as the place where we convert snake_case (from the db) to camelCase (in the application). This means our interfaces and types are all camelCase as expected. This has meant cascading (noisy) changes to code and tests but it seemed worthwhile over introducing more snake_case properties to types.
Allow
$api
client for side-effects triggered by permission-scoped users (such as writing audit logs). The alternative here would be to increase public client scope and add backend-only mutations - see previous thoughts on this here.