-
Notifications
You must be signed in to change notification settings - Fork 89
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
feat(backend): backend tenant graphql resolvers #3234
base: 2893/multi-tenancy-v1
Are you sure you want to change the base?
Conversation
23e34b2
to
99d6982
Compare
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.
The code in the PR looks good.
Just the Bruno collection to be added.
"Fetch a paginated list of tenants on the instance." | ||
tenants( |
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.
Should probably mention this is for operators only. I also wondered about using a new isOperator
directive instead of throwing in the resolver. Not sure it matters much but I wonder if the generated docs would pick it up. Maybe not much point unless we have more resolvers that use it though.
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 guess the createTenant
is operator only as well. So should probably note it there in the same way.
beforeAll(async (): Promise<void> => { | ||
deps = await initIocContainer({ | ||
...Config, | ||
databaseUrl: process.env.TENANT_TEST_DATABASE_URL as string |
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.
Why do we need this separate db instead of just using TEST_DATABASE_URL
?
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 added another test database to handle pagination tests correctly for tenants. Pagination tests need to truncate the tables between tests in order to work properly - if we do this on the same database as the other tests, that will break the ones that require the existence of an operator tenant to work, as it will have been deleted.
I realize that the pagination tests will be testing a scenario that shouldn't happen, but I feel like it makes sense to do it this way to make sure that pagination works correctly.
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 think you can get away with this by using e.g. dbSchema
config instead. This is how I ended up solving this (comment).
@@ -1493,6 +1527,75 @@ type CancelIncomingPaymentResponse { | |||
payment: IncomingPayment | |||
} | |||
|
|||
type Tenant implements Model { |
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.
Looking at the create tenants migration, email
, idpConsentUrl
and idpSecret
(in the model and the create input) should be optional
test('Cannot get page as non-operator', async (): Promise<void> => { | ||
const tenant = await createTenant(deps) | ||
const apolloClient = createTenantedApolloClient(appContainer, tenant.id) | ||
try { |
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.
try { | |
try { | |
expect.assertions(2) |
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.
(same for a few tests below)
beforeAll(async (): Promise<void> => { | ||
deps = await initIocContainer({ | ||
...Config, | ||
databaseUrl: process.env.TENANT_TEST_DATABASE_URL as string |
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 think you can get away with this by using e.g. dbSchema
config instead. This is how I ended up solving this (comment).
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.
LGTM.
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.
https://github.com/interledger/rafiki/actions/runs/12996726301/job/36246174979?pr=3234
Just need to look at the unit and integration tests failing.
@@ -3,6 +3,8 @@ set -e | |||
|
|||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | |||
DROP DATABASE IF EXISTS TESTING; | |||
DROP DATABASE IF EXISTS TENANT_TESTING; |
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.
These can be removed as well
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.
(still applies)
@@ -148,6 +148,26 @@ type Query { | |||
"Unique identifier of the receiver (incoming payment URL)." | |||
id: String! | |||
): Receiver | |||
|
|||
"Retrieve a tenant of the instance." | |||
tenant("Unique identifier of the tenant." id: String!): Tenant |
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.
tenant("Unique identifier of the tenant." id: String!): Tenant | |
tenant("Unique identifier of the tenant." id: String!): Tenant! |
Since resolver throws if the tenant isn't found
${true} | ${'operator'} | ||
${false} | ${'tenant'} | ||
`( | ||
'Can delete a tenant as $description', |
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.
Does this mean a tenant can delete itself?
If so, do you think should it be reserved only for operators?
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.
Making deleteTenant operator-only as per call today.
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.
LGTM.
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.
A few final things
@@ -1,4 +1,4 @@ | |||
process.env.LOG_LEVEL = 'silent' | |||
process.env.LOG_LEVEL = 'info' |
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.
maybe we leave it as silent
to keep the test output tidy
@@ -3,6 +3,8 @@ set -e | |||
|
|||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | |||
DROP DATABASE IF EXISTS TESTING; | |||
DROP DATABASE IF EXISTS TENANT_TESTING; |
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.
(still applies)
${false} | ${'tenant'} | ||
`('whoami query as $description', async ({ isOperator }): Promise<void> => { | ||
const tenant = await createTenant(deps) | ||
console.log('created tenant') |
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.
console.log('created tenant') |
Changes proposed in this pull request
whoami
tenant
tenants
createTenant
updateTenant
deleteTenant
Context
Fixes #3124.
Checklist
fixes #number
user-docs
label (if necessary)