Skip to content
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

fix: subscriptions payloads _entity w/ relations fields #2626

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

IcanDivideBy0
Copy link
Contributor

@IcanDivideBy0 IcanDivideBy0 commented Dec 11, 2024

Description

With recent changes to subscriptions, the _entity field is now graphql-typed, but the said field is resolved with raw data from database, hence all camelCase named fields in the gql schema are not properly resolved. This PR solves this issue.

Nonetheless all requested relations of the _entity are still not properly resolved... I'll try working on that now... if you have any advice regarding this, that'd be great :)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • I have tested locally
  • I have performed a self review of my changes
  • Updated any relevant documentation
  • Linked to any relevant issues
  • I have added tests relevant to my changes
  • Any dependent changes have been merged and published in downstream modules
  • My code is up to date with the base branch
  • I have updated relevant changelogs. We suggest using chan

Copy link
Collaborator

@stwiname stwiname left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im happy with this change. Can you please update the changelog too.

For getting relations working, i think the goal would be to take the id from the payload and use that to run a graphql query and not use anything from the _entity. I don't have much direction to give here, postgraphile is not trivial to work with. But the realtime feature might be a good reference as to how this could be implemented.

@IcanDivideBy0 IcanDivideBy0 force-pushed the subscription-camelcase-fields branch from fa8f030 to 4a6ccd7 Compare December 12, 2024 16:25
@IcanDivideBy0
Copy link
Contributor Author

IcanDivideBy0 commented Dec 12, 2024

I've updated the changelog.

I tried to get relations working too, from what I see in postgraphile documentation, I should be able to get it working with something like this in the resolver

        const [row] = await resolveInfo.graphile.selectGraphQLResultFromTable(
          sql.fragment`${table.namespace.name}.${table.name}`,
          (tableAlias, queryBuilder) => {
            queryBuilder.where(
              sql.fragment`${tableAlias}.id = ${sql.value(parent.id)}`
            )
            queryBuilder.limit(1);
          }
        );

        return row;

unfortunately i always end up with an error Cannot destructure property 'pgClient' of 'context' as it is undefined. ... for some reason the context is always undefined in subscriptions resolvers ... i then tried to update apollo server to use the latest @apollo/server but the error still there :/

@IcanDivideBy0
Copy link
Contributor Author

Ok I found the problem, context was missing from useServer options on web socket server.
Then I spent way too much time debugging why the selectGraphQLResultFromTable was not returning the relations to find out that historical data were messing up the query. I've just added a quick n dirty fix to set a high enough (for me) block height to the queryBuilder context... there should be a better way, please let me know how (by adding it to the returned _entity from the notifier ?)

@IcanDivideBy0 IcanDivideBy0 changed the title fix: subscriptions payloads _entity w/ camelCase fields fix: subscriptions payloads _entity w/ relations fields Dec 12, 2024
@IcanDivideBy0 IcanDivideBy0 force-pushed the subscription-camelcase-fields branch from a431070 to 17e2381 Compare December 12, 2024 20:29
@IcanDivideBy0
Copy link
Contributor Author

IcanDivideBy0 commented Dec 13, 2024

I'm thinking of removeing these two lines: https://github.com/subquery/subql/blob/main/packages/node-core/src/db/sync-helper.ts#L197-L198 and use the _id in the where clause and the _block_range.startfor the query builder context. Do you agree on this ?

@stwiname
Copy link
Collaborator

I'm thinking of removeing these two lines: https://github.com/subquery/subql/blob/main/packages/node-core/src/db/sync-helper.ts#L197-L198 and use the _id in the where clause and the _block_range.startfor the query builder context. Do you agree on this ?

I see no issue with that

@IcanDivideBy0 IcanDivideBy0 force-pushed the subscription-camelcase-fields branch from 17e2381 to 48dc0c9 Compare December 16, 2024 09:02
@IcanDivideBy0
Copy link
Contributor Author

ready for a final review :)

Copy link
Collaborator

@stwiname stwiname left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, can you please update the changelog for node-core then this can be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants