twentyhq / twenty

Building a modern alternative to Salesforce, powered by the community.
https://twenty.com
Other
23.51k stars 2.43k forks source link

GraphQL API query fails with error ""Cannot read properties of undefined (reading 'fromField')"" #8571

Open rob-luke opened 1 week ago

rob-luke commented 1 week ago

Bug Description

After updating to v0.32.4 (big thank you @charlesBochet !!!), I am unable to use the graphql api interface.

If I try by the web interface it fails like this...

Image

and I get the following errors in the logs

Exception Captured

  {

    operation: { name: 'FindCompany', type: 'query' },

    document: 'query FindCompany {\n' +

      '  companies(filter: {name: {startsWith: "Twenty"}}) {\n' +

      '    edges {\n' +

      '      node {\n' +

      '        id\n' +

      '        name\n' +

      '      }\n' +

      '    }\n' +

      '  }\n' +

      '}',

    user: undefined

  }

  [

    TypeError: Cannot read properties of undefined (reading 'fromField')

        at ProcessAggregateHelper.addSelectedAggregatedFieldsQueriesToQueryBuilder (/app/packages/twenty-server/dist/src/engine/api/graphql/graphql-query-runner/helpers/process-aggregate.helper.js:16:78)

        at GraphqlQueryFindManyResolverService.resolve (/app/packages/twenty-server/dist/src/engine/api/graphql/graphql-query-runner/resolvers/graphql-query-find-many-resolver.service.js:85:32)

        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

        at async GraphqlQueryRunnerService.executeQuery (/app/packages/twenty-server/dist/src/engine/api/graphql/graphql-query-runner/graphql-query-runner.service.js:135:25)

        at async descriptor.value (/app/packages/twenty-server/dist/src/engine/decorators/observability/log-execution-time.decorator.js:18:28)

        at async Object.companies (/app/packages/twenty-server/dist/src/engine/api/graphql/workspace-resolver-builder/factories/find-many-resolver.factory.js:34:24)

        at async field.resolve (/app/node_modules/@envelop/on-resolve/cjs/index.js:36:42)

        at async /app/node_modules/@graphql-tools/executor/cjs/execution/promiseForObject.js:18:35

        at async Promise.all (index 0) {

      path: undefined,

      locations: undefined,

      extensions: {

        code: 'INTERNAL_SERVER_ERROR',

        response: "Cannot read properties of undefined (reading 'fromField')"

      }

    }

  ]

The same thing happens if I call the api via code.

Expected behavior

The query should run without an exception in the logs.

Conclusion

Thank you for the help. Please let me know if I can provide additional information.

rob-luke commented 6 days ago

Incase its relevant, I am also seeing this error in the logs

[Nest] 1  - 11/18/2024, 11:52:14 PM     LOG [GraphqlQueryRunnerService:findMany] Execution time: 81.30ms

fetching object metadata: 139.1ms

generating object metadata map: 1.451ms

[Nest] 1  - 11/19/2024, 1:37:04 AM     LOG [WorkspaceMetadataCacheService:recomputeMetadataCache] Execution time: 194.75ms

Exception Captured

  { user: undefined }

  [

    GraphqlQueryRunnerException [Error]: Object metadata collection not found

        at WorkspaceSchemaFactory.createGraphQLSchema (/app/packages/twenty-server/dist/src/engine/api/graphql/workspace-schema.factory.js:53:19)

        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

        at async GraphQLConfigService.createSchema (/app/packages/twenty-server/dist/src/engine/api/graphql/graphql-config/graphql-config.service.js:174:16)

        at async conditionalSchema (/app/packages/twenty-server/dist/src/engine/api/graphql/graphql-config/graphql-config.service.js:112:28)

        at async schema (/app/node_modules/@graphql-yoga/nestjs/dist/cjs/index.js:68:95)

        at async onRequestParseDone (/app/node_modules/graphql-yoga/cjs/plugins/use-schema.js:39:36)

        at async YogaServer.handle (/app/node_modules/graphql-yoga/cjs/server.js:70:17) {

      code: 'METADATA_CACHE_VERSION_NOT_FOUND'

    }

  ]

[Nest] 1  - 11/19/2024, 1:38:08 AM     LOG [TypeDefinitionsGenerator] Generating composite type objects: [LINKS, CURRENCY, FULL_NAME, ADDRESS, ACTOR, EMAILS, PHONES]

[Nest] 1  - 11/19/2024, 1:38:08 AM     LOG [TypeDefinitionsGenerator] Generating metadata objects: [messageChannelMessageAssociation, timelineActivity, person, opportunity, apiKey, viewFilter, auditLog, attachment, blocklist, calendarEvent, calendarChannel, calendarChannelEventAssociation, calendarEventParticipant, messageChannel, connectedAccount, favorite, viewField, viewSort, view, webhook, workspaceMember, messageThread, message, messageParticipant, company, note, noteTarget, task, taskTarget, viewGroup, viewFilterGroup]
charlesBochet commented 6 days ago

@rob-luke I'm a bit worried you might actually have main / 0.33-canary version (which is unstable). I'll look into what has been push behind v0.32.4 today

rob-luke commented 6 days ago

I just triple confirmed and I am using image image: twentycrm/twenty:v0.32.4, so it may be as you suspected, that something in main leaked in to the release. @charlesBochet

rob-luke commented 5 days ago

Hi @charlesBochet I did some more digging in to this.

charlesBochet commented 5 days ago

Yes we have an issue with v0.32.4, I'm investigating

rob-luke commented 5 days ago

Thanks. Let me know if I can help.