GraphQLError: Variable "$orderBy" got invalid value { position: "AscNullsFirst" }; Field "position"

Testing upgrade from 0.3.0 to 0.3.1 we get this error. I have added the field "position" to company/people/opportunities but I am still getting it. I suspect it might be an issue with updating the TypeORM layer but I am not sure if this is the actual issue. Is there a way to add this Field and continue with the current data?
86 Replies
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
GraphQLError: Variable "$orderBy" got invalid value { position: "AscNullsFirst" }; Field "position" is not defined by type "CompanyOrderByInput".
at createGraphQLError (/app/node_modules/@graphql-tools/executor/node_modules/@graphql-tools/utils/cjs/errors.js:31:12)
at /app/node_modules/@graphql-tools/executor/cjs/execution/values.js:73:52
at coerceInputValueImpl (/app/node_modules/graphql/utilities/coerceInputValue.js:131:9)
at coerceInputValue (/app/node_modules/graphql/utilities/coerceInputValue.js:32:10)
at coerceVariableValues (/app/node_modules/@graphql-tools/executor/cjs/execution/values.js:68:65)
at getVariableValues (/app/node_modules/@graphql-tools/executor/cjs/execution/values.js:19:25)
at buildExecutionContext (/app/node_modules/@graphql-tools/executor/cjs/execution/execute.js:171:69)
at execute (/app/node_modules/@graphql-tools/executor/cjs/execution/execute.js:32:24)
at /app/node_modules/@graphql-tools/executor/cjs/execution/normalizedExecutor.js:15:81
at new ValueOrPromise (/app/node_modules/@graphql-tools/executor/node_modules/value-or-promise/build/main/ValueOrPromise.js:14:21) {
path: undefined,
locations: [ [Object] ],
extensions: { http: [Object] }
}
]
GraphQLError: Variable "$orderBy" got invalid value { position: "AscNullsFirst" }; Field "position" is not defined by type "CompanyOrderByInput".
at createGraphQLError (/app/node_modules/@graphql-tools/executor/node_modules/@graphql-tools/utils/cjs/errors.js:31:12)
at /app/node_modules/@graphql-tools/executor/cjs/execution/values.js:73:52
at coerceInputValueImpl (/app/node_modules/graphql/utilities/coerceInputValue.js:131:9)
at coerceInputValue (/app/node_modules/graphql/utilities/coerceInputValue.js:32:10)
at coerceVariableValues (/app/node_modules/@graphql-tools/executor/cjs/execution/values.js:68:65)
at getVariableValues (/app/node_modules/@graphql-tools/executor/cjs/execution/values.js:19:25)
at buildExecutionContext (/app/node_modules/@graphql-tools/executor/cjs/execution/execute.js:171:69)
at execute (/app/node_modules/@graphql-tools/executor/cjs/execution/execute.js:32:24)
at /app/node_modules/@graphql-tools/executor/cjs/execution/normalizedExecutor.js:15:81
at new ValueOrPromise (/app/node_modules/@graphql-tools/executor/node_modules/value-or-promise/build/main/ValueOrPromise.js:14:21) {
path: undefined,
locations: [ [Object] ],
extensions: { http: [Object] }
}
]
charles
charlesโ€ข10mo ago
Hi @๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด, so it's not documented yet as this is super experimental but you can play with workspace:health (to make sure your workspace postgres schema is a healthy state compared to your metadata) and workspace:sync-metadata commands to upgrade it to the latest stages. I'm quite sure this won't fully work but it should help I'm interested into helping your migrate to the new version to see how good/bad the tooling is right now Could you start by giving me the output of npx nx command -- workspace:health -w {YOUR_WORKSPACE_ID} -d ? (it should write some logs into /logs folder
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Should there be something after -d?
charles
charlesโ€ข10mo ago
nope the -d is not properly named (it's dry-run but it should actually be something like --verbose)
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Cannot find project 'workspace_6zezc5oiagj6yqldcepfgb226' Cannot find project '{workspace_6zezc5oiagj6yqldcepfgb226}'
charles
charlesโ€ข10mo ago
you need to put your workspace.id not your workspace schema name
charles
charlesโ€ข10mo ago
no worries, it's not documented so... ๐Ÿ˜„
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Where do I find the id? I've seen it but can't remember where Is it on the invite screen?
charles
charlesโ€ข10mo ago
you'll need to either check it in your database, or in your nework table /graphql responses (you should see some information about the currentWorkspace and its id)
charles
charlesโ€ข10mo ago
No description
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Found the id 75f6e77a-ec52-43fd-af2b-5e1ca8319b2e but no metter how I write it I get "Cannot find project" Should the {} be there or was that your way of stating <insert-here> ?
charles
charlesโ€ข10mo ago
was my way of saying insert there
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Cannot find project '75f6e77a-ec52-43fd-af2b-5e1ca8319b2e'
charles
charlesโ€ข10mo ago
You need to be in the server folder to execute it ~/dev/twenty/twenty/packages/twenty-server > npx nx command -- workspace:health -w 20202020-1c25-4d02-bf25-6aeccf7ea419 -d [Nest] 58070 - 03/15/2024, 3:38:05 PM LOG [WorkspaceHealthCommand] Workspace is not healthy, found 1 issues [Nest] 58070 - 03/15/2024, 3:38:05 PM LOG [WorkspaceHealthCommand] Issues written to log
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Resetting our test-env to see if my trying to fix it has broken the broken state ๐Ÿ™‚ No difference after reset
/app/packages/twenty-server # npx nx command --workspace:health -w 75f6e77a-ec52-43fd-af2b-5e1ca8319b2e -d

> NX Cannot find project '75f6e77a-ec52-43fd-af2b-5e1ca8319b2e'
/app/packages/twenty-server # npx nx command --workspace:health -w 75f6e77a-ec52-43fd-af2b-5e1ca8319b2e -d

> NX Cannot find project '75f6e77a-ec52-43fd-af2b-5e1ca8319b2e'
charles
charlesโ€ข10mo ago
sorry, my bad, you need to add a space after --
charles
charlesโ€ข10mo ago
you can also run it directly (without nx) if you haven't made any modification by running yarn command workspace:health nx is meant for dev mode and yarn command for prod
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Workspace is not healthy, found 10 issues
2 Feb 15 16:59 workspace-health-default-value-metadata-entities.json
8668 Feb 15 16:59 workspace-health-default-value-migrations.json
25286 Feb 15 17:02 workspace-health-issues-20202020-1c25-4d02-bf25-6aeccf7ea419.json
20159 Mar 15 14:43 workspace-health-issues-75f6e77a-ec52-43fd-af2b-5e1ca8319b2e.json
2 Feb 15 16:53 workspace-health-nullable-metadata-entities.json
839 Feb 15 16:53 workspace-health-nullable-migrations.json
2128 Feb 15 17:02 workspace-health-target-column-map-metadata-entities.json
2 Feb 15 17:02 workspace-health-target-column-map-migrations.json
2 Feb 15 16:59 workspace-health-default-value-metadata-entities.json
8668 Feb 15 16:59 workspace-health-default-value-migrations.json
25286 Feb 15 17:02 workspace-health-issues-20202020-1c25-4d02-bf25-6aeccf7ea419.json
20159 Mar 15 14:43 workspace-health-issues-75f6e77a-ec52-43fd-af2b-5e1ca8319b2e.json
2 Feb 15 16:53 workspace-health-nullable-metadata-entities.json
839 Feb 15 16:53 workspace-health-nullable-migrations.json
2128 Feb 15 17:02 workspace-health-target-column-map-metadata-entities.json
2 Feb 15 17:02 workspace-health-target-column-map-migrations.json
ugh
charles
charlesโ€ข10mo ago
ok not so bad :p
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Was more the formatting I was annoyed at ๐Ÿ™‚
charles
charlesโ€ข10mo ago
yeah ๐Ÿ˜„ that's why we are not bragging about it could you paste the output of workspace-health-issues-75f6e77a-ec52-43fd-af2b-5e1ca8319b2e.json ?
charles
charlesโ€ข10mo ago
Ok Have you made a dump of your database?
charles
charlesโ€ข10mo ago
we will try to fix it (it should not destroy anything but let's be super safe) Ok
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Don't worry we have test-env
charles
charlesโ€ข10mo ago
ok ๐Ÿ™‚ Let's try: yarn command workspace:health --workspace-id {your_workspace_id} --fix default-value
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
(running prerelease 0.x software is bad enough :))
charles
charlesโ€ข10mo ago
we have stabilized the way we handled default-value in 0.3.2 so the health check detects some issue in previous previous versions. This command should fix most of them
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Ah this is 0.3.0-> 0.3.1 should I reset and try 0.3.0->0.3.2 directly?
charles
charlesโ€ข10mo ago
yes you can go to 0.3.2 directly I can guide you through the breaking changes we are releasing 0.3.3 this week-end or on Monday (we are releasing every two weeks)
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
The migration scripts (yarn database:migrate) are automatically run btw if that messes with this process (I'm assuming it shouldn't but worth pointing out)
charles
charlesโ€ข10mo ago
yep, these should not be a problem
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
yarn command workspace:health --workspace-id 75f6e77a-ec52-43fd-af2b-5e1ca8319b2e --fix default-value -d Usage Error: Couldn't find a script named "command". package.json looks different I think - not sure
charles
charlesโ€ข10mo ago
yep replace yarn command by node dist/src/command.js
charles
charlesโ€ข10mo ago
are you on twenty-server folder?
charles
charlesโ€ข10mo ago
do you have a dist folder? (I'm not sure what's your setup)
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
No, using the prebuilt docker images you provide
charles
charlesโ€ข10mo ago
weird, i'm quite sure there is a dist folder in the prebuilt-docker image CMD ["node", "dist/src/main"] (that's the command that is launched at the end of the dockerfile)
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
You are correct. It's user error. Fixing it
charles
charlesโ€ข10mo ago
ok ๐Ÿ™‚
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Workspace is not healthy, found 37 issues
charles
charlesโ€ข10mo ago
ok could you paste the output? same file
charles
charlesโ€ข10mo ago
Ok, so you have the 10 issues because of defaultValue + 27 because we also have clarified the delete onCascade behaviors for the first one we have a fix command (the one I gave you earlier) that you can run. For the other one we are going to ignore it for now and get back to it later
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
But shouldn't the 10 issues disappear when i run with --fix default-value? Ah removing -d (dryrun-ish) fixed them
[Nest] 343 - 03/15/2024, 3:25:25 PM LOG [WorkspaceHealthCommand] Workspace is not healthy, found 37 issues
[Nest] 343 - 03/15/2024, 3:25:25 PM LOG [WorkspaceHealthCommand] Fixing issues
[Nest] 343 - 03/15/2024, 3:25:26 PM LOG [WorkspaceHealthCommand] Fixed 10/37 issues
[Nest] 343 - 03/15/2024, 3:25:25 PM LOG [WorkspaceHealthCommand] Workspace is not healthy, found 37 issues
[Nest] 343 - 03/15/2024, 3:25:25 PM LOG [WorkspaceHealthCommand] Fixing issues
[Nest] 343 - 03/15/2024, 3:25:26 PM LOG [WorkspaceHealthCommand] Fixed 10/37 issues
charles
charlesโ€ข10mo ago
ok cool
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
This repeats though if I run it again
charles
charlesโ€ข10mo ago
ok
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
So I 'm not sure the fix is comitted
charles
charlesโ€ข10mo ago
let's run the health check without --fix again and see if we only have 27 issues?
charles
charlesโ€ข10mo ago
ok weird give me 1 sec
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
"[Nest] 750 - 03/15/2024, 3:48:47 PM LOG [WorkspaceHealthCommand] Workspace is not healthy, found 37 issues Segmentation fault (core dumped) " This seems bad
charles
charlesโ€ข10mo ago
ok, let's ignore these for now I don't want to invest into fixing it as they might be fix by the upgrade
charles
charlesโ€ข10mo ago
So, let's move to the next step of the process and get back to the health check later can you do: node dist/src/command.js workspace:sync-metadata --workspace-id 75f6e77a-ec52-43fd-af2b-5e1ca8319b2e -d (here the -d is important as it will enable us to check what's going to happen) The idea is to migrate a given workspace to the last version of Twenty schema then we should have a new folder in logs
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Issues found - aborting. Should I --force?
charles
charlesโ€ข10mo ago
yes!
charles
charlesโ€ข10mo ago
ok, could you send me the files? actually, just the delete ones? the other are not worrying :p
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Easier to pack them all
charles
charlesโ€ข10mo ago
looks good let's run it without -d
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
I can see our data again!
charles
charlesโ€ข10mo ago
wonderful! let's run the health-check again ๐Ÿ™‚
charles
charlesโ€ข10mo ago
looks reasonable, could you paste the output?
charles
charlesโ€ข10mo ago
ok! So we still have mismatch between what's in metadata.relationMetadata table and what we have in our workspace postgres schema metadata.relationMetadata is up-to-date and the health check is saying: be careful the onDelete behavior is different so what you need to do is to manually go to each of these foreign keys and update the onCascade in your postgres preferred UI / cli the easiest way to get to know what to update is to take a look at the "columnStructure" + "relationMetadata" fields For example for the first one: "relationMetadata": { "id": "8ebdd390-cd55-431e-9f27-5034f6d93f0c", "relationType": "ONE_TO_MANY", "onDeleteAction": "SET_NULL", "fromObjectMetadataId": "c3643370-d13a-4f97-aece-6b429df5ee98", "toObjectMetadataId": "22426d48-9f33-4f08-8039-14d409186aab", "fromFieldMetadataId": "6d7a8099-c411-4284-a9ee-10c3ec3b52f1", "toFieldMetadataId": "fec30d5d-6b1c-4705-bc15-02d4f06890e2", "workspaceId": "75f6e77a-ec52-43fd-af2b-5e1ca8319b2e", "createdAt": "2024-01-30T11:06:04.896Z", "updatedAt": "2024-01-30T11:06:04.896Z" }, "columnStructure": { "tableSchema": "workspace_6zezc5oiagj6yqldcepfgb226", "tableName": "activityTarget", "columnName": "activityId", "dataType": "uuid", "isNullable": true, "columnDefault": null, "isPrimaryKey": false, "isForeignKey": true, "isUnique": false, "onUpdateAction": "NO ACTION", "onDeleteAction": "CASCADE" }, It means that activityTarget.activityId FK is set as NO_ACTION in your postgres workspace schema VS SET_NULL in your metadata.relationMetadata ==> you should set it to SET_NULL once done, your workspace should be healthy! Ideally in the next releases, your workspace will keep being healthy and you'll just have to run the sync-metadata command and that's it!
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Will do. After each release I should do migrate+sync metadata or just sync?
charles
charlesโ€ข10mo ago
typeorm:migrate (this will migrate everything except the workspace schemas) + sync-metadata
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
@charles I got almost all the way. I believe I managed to fix all the relations (no more errors) but we have created a object (type?) called Key/Keys that a company can have 0..N of. When I try to access this "Keys" object I get:
` GraphQLError: Variable "$orderBy" got invalid value { position: "AscNullsFirst" }; Field "position" is not defined by type "KeyOrderByInput
` GraphQLError: Variable "$orderBy" got invalid value { position: "AscNullsFirst" }; Field "position" is not defined by type "KeyOrderByInput
` Workspace is reporting "Healthy" though.
charles
charlesโ€ข10mo ago
I think you are missing a "position" field of type POSITION on your Key object this should be captured by the sync-metadata, can you dry run the sync-metadata again and give me the output of fields-create, and fields-update?
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
node dist/src/command.js workspace:sync-metadata --workspace-id 75f6e77a-ec52-43fd-af2b-5e1ca8319b2e -d gives empty files in logs/sync-work... cat logs/sync-workspace-logger-service/* [][][][][][][][][][]
charles
charlesโ€ข10mo ago
you are on 0.3.2 right?
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
yes, might I be missing a restart or something simple?
charles
charlesโ€ข10mo ago
I am not sure Could you look into your workspace schema and see if you have a position column on your key table?
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
No it's not there
Table "workspace_6zezc5oiagj6yqldcepfgb226._key"
Column | Type | Collation | Nullable | Default
-------------+-----------------------------+-----------+----------+--------------------
id | uuid | | not null | uuid_generate_v4()
createdAt | timestamp without time zone | | not null | now()
updatedAt | timestamp without time zone | | not null | now()
deletedAt | timestamp without time zone | | |
name | text | | not null | 'Untitled'::text
_expiryDate | timestamp without time zone | | |
_companyId | uuid | | |
Indexes:
"PK_5ecaac5739fce037a06dc997484" PRIMARY KEY, btree (id)
Foreign-key constraints:
"FK_802d964143765f810821db1a9be" FOREIGN KEY ("_companyId") REFERENCES workspace_6zezc5oiagj6yqldcepfgb226.company(id) ON DELETE SET NULL
Referenced by:
TABLE "workspace_6zezc5oiagj6yqldcepfgb226."activityTarget"" CONSTRAINT "FK_3927491a450a1540938319c58ef" FOREIGN KEY ("_keyId") REFERENCES workspace_6zezc5oiagj6yqldcepfgb226._key(id) ON DELETE SET NULL
TABLE "workspace_6zezc5oiagj6yqldcepfgb226.favorite" CONSTRAINT "FK_4be8683fa7e516cb5eae4d29941" FOREIGN KEY ("_keyId") REFERENCES workspace_6zezc5oiagj6yqldcepfgb226._key(id) ON DELETE SET NULL
Table "workspace_6zezc5oiagj6yqldcepfgb226._key"
Column | Type | Collation | Nullable | Default
-------------+-----------------------------+-----------+----------+--------------------
id | uuid | | not null | uuid_generate_v4()
createdAt | timestamp without time zone | | not null | now()
updatedAt | timestamp without time zone | | not null | now()
deletedAt | timestamp without time zone | | |
name | text | | not null | 'Untitled'::text
_expiryDate | timestamp without time zone | | |
_companyId | uuid | | |
Indexes:
"PK_5ecaac5739fce037a06dc997484" PRIMARY KEY, btree (id)
Foreign-key constraints:
"FK_802d964143765f810821db1a9be" FOREIGN KEY ("_companyId") REFERENCES workspace_6zezc5oiagj6yqldcepfgb226.company(id) ON DELETE SET NULL
Referenced by:
TABLE "workspace_6zezc5oiagj6yqldcepfgb226."activityTarget"" CONSTRAINT "FK_3927491a450a1540938319c58ef" FOREIGN KEY ("_keyId") REFERENCES workspace_6zezc5oiagj6yqldcepfgb226._key(id) ON DELETE SET NULL
TABLE "workspace_6zezc5oiagj6yqldcepfgb226.favorite" CONSTRAINT "FK_4be8683fa7e516cb5eae4d29941" FOREIGN KEY ("_keyId") REFERENCES workspace_6zezc5oiagj6yqldcepfgb226._key(id) ON DELETE SET NULL
`
charles
charlesโ€ข10mo ago
we might have an issue with our sync scripts for custom objects. We will dig into it tomorrow in the mean time if you don't have any important data into this table, you might just want to drop it and create a new object it should have the position field I think there was a bug that should be fixed in 0.3.3 released tomorrow but I'm unsure
๐Ÿ…น๐Ÿ…ฐ๐Ÿ†ˆ๐Ÿ…ฑ๐Ÿ…ด๐Ÿ…ด
Can I just drop table in postgres or do I need to go through UI? Ah I found the ui for it now. Had to deactivate first I ยดll just drop and recreate if we go forward in using it. Until then it can stay until 0.3.3 for a possible bug report Thank you for your help
charles
charlesโ€ข10mo ago
You are welcome!
Want results from more Discord servers?
Add your server