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

Add test with graphql and sqlite storage #6782

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

mapineaultvooban
Copy link

@mapineaultvooban mapineaultvooban commented Jan 23, 2025

the _attachments is leaked in the graphql payload

This PR contains:

A unit test that executes a migration on a database with a sqlite storage. Then a graphql server sends an update with leaked property (assumedMasterState contains the _attachments property). I wrote some comments in the test, because I don't have access to the premium package (RxStorageSQLite) in this repository.

When we use a different storage (e.g in memory or another default storage in the public package), the test passed.

Describe the problem you have without this PR

In our project, we use a RxDatabase with

  • a Sqlite storage (RxStorageSQLite from the premium package)
  • a graphQL server to push updates to our backend

In one of our schemas, we add a new migration. when executed, it seems that the _attachments property is followed. When a user updates a property in an entity, the graphQL server push the update to our backend, causing an error in the serialization (input -> classes).

image

Here is a payload of one of our shemas with the problem. In the entity's masterState, we can see that the _attachments property is leaked.

{
  "query": "mutation PushContractAgreements($pushRows: [PushRowContractAgreementInput!]!) {
    pushContractAgreements(contractAgreements: $pushRows) {
        id
        status
        date
        number
        lunchBreaks {
          from
          durationInMinutes
          startsOnNextDay
        }
        signature
        signedAt
        updatedAt
        isDeleted
    }
  }",
  "operationName": "PushContractAgreements",
  "variables": {
    "pushRows": [
      {
        "assumedMasterState": {
          "id": "c3fdbc58-4588-4fe4-a3b4-e0e5467e1d82",
          "status": "created",
          "date": "2025-01-23T12:00:00.000Z",
          "number": null,
          "lunchBreaks": [],
          "signature": null,
          "signedAt": null,
          "updatedAt": 1737640220258,
          "_attachments": {},
          "isDeleted": false
        },
        "newDocumentState": {
          "id": "c3fdbc58-4588-4fe4-a3b4-e0e5467e1d82",
          "status": "ongoing",
          "date": "2025-01-23T12:00:00.000Z",
          "number": null,
          "lunchBreaks": [],
          "signature": null,
          "signedAt": null,
          "updatedAt": 1737647944354,
          "isDeleted": false
        }
      }
    ]
  }
}

Here is our database setup

db = await createRxDatabase<RxGuayCollections>({
     eventReduce: true,
     multiInstance: false,
     name: dbName,
     password: env.DATABASE_PASSWORD,
     storage: getRxStorageSQLite({
       sqliteBasics: getSQLiteBasicsExpoSQLiteAsync(ExpoSqliteStorageNext.openDatabaseAsync),
       // log: console.log.bind(console),
     }),
     ignoreDuplicate: isTest,
     cleanupPolicy: {
       minimumDeletedTime: 1000 * 60 * 60 * 24 * 31, // one month,
       minimumCollectionAge: 1000 * 60, // 60 seconds
       runEach: 1000 * 60 * 5, // 5 minutes
       awaitReplicationsInSync: true,
       waitForLeadership: false,
     },
     allowSlowCount: true,
   });

db.addCollections({
     contract_agreement: {
       autoMigrate: true,
       migrationStrategies: {
         1: (doc: never): never => doc,
       },
       schema: {
         description: 'describes a contract agreement',
         keyCompression: true,
         primaryKey: 'id',
         indexes: ['updatedAt'],
         properties: {
           id: {
             maxLength: 100,
             type: 'string', // <- the primary key must have set maxLength
           },
           isDeleted: {
             type: 'boolean',
           },
           lunchBreaks: {
             items: {
               description: 'describes a time range',
               properties: {
                 from: {
                   type: 'string',
                 },
                 durationInMinutes: {
                   type: 'number',
                 },
                 startsOnNextDay: {
                   type: 'boolean',
                 },
               },
               type: 'object',
             },
             type: 'array',
           },
           number: {
             type: ['null', 'number'],
           },
           signature: {
             type: ['string', 'null'],
           },
           signedAt: {
             type: ['string', 'null'],
           },
           status: {
             type: 'string',
           },
           updatedAt: {
             type: 'number',
             minimum: 0,
             maximum: 99999999999999,
             multipleOf: 1,
           },
         },
         required: ['id', 'status'],
         title: 'Contract agreement schema',
         type: 'object',
         version: 1,
       },
     },
   });

Todos

  • Tests
  • Documentation
  • Typings
  • Changelog

the _attachments is leaked in the graphql payload
});
};

const dbName = randomCouchString(10);
Copy link
Owner

Choose a reason for hiding this comment

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

randomCouchString is called randomToken in RxDB v16.

Copy link
Author

@mapineaultvooban mapineaultvooban Jan 24, 2025

Choose a reason for hiding this comment

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

I created this branch based on RxDB 15.39, because we are not ready to switch to RxDB 16 yet (we will switch to the version 16 eventually). Would it be possible to fix this issue in RxDB 15.39?

randomToken is not available in RxDB 15.39

@pubkey
Copy link
Owner

pubkey commented Jan 24, 2025

Hi @mapineaultvooban
Thank you for reporting. Please fix the CI issues here.
These tests internally also run with the premium storages, so if the CI is green here, I can check what is going on with SQLite.

pubkey and others added 8 commits January 24, 2025 21:22
* OnPage SEO

* ADD stuff

* ADD meta data

* FIX sidebar titles

* ADD internal links
* OnPage SEO

* ADD stuff

* ADD meta data

* FIX sidebar titles

* ADD internal links

* ADD landingpage indexeddb v2
the _attachments is leaked in the graphql payload
…tachment' into graphql_replication_attachment
…ation_attachment' into graphql_replication_attachment"

This reverts commit 9911f50, reversing
changes made to 9f85889.
@pubkey
Copy link
Owner

pubkey commented Jan 27, 2025

I am sorry but this PR has 528 changed files and is unreadable. Please rebase or recreate. Also please never commit files from the dist folder.

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