prisma / prisma-admin-feedback

Feedback for Prisma Admin (currently in invite-only preview)
6 stars 1 forks source link

Prisma admin UI caches old datamodel in local storage #129

Open thecodeboss opened 5 years ago

thecodeboss commented 5 years ago

Describe the bug After running a migration, we started seeing errors in Prisma Admin related to the previous version of the schema. Basically changes we made in the migration were not reflected in the UI, and it was still sending invalid queries to the Prisma server.

After some debugging, I found the issue was that the admin UI was caching the datamodel in my browser's local storage. I am able to resolve the issue by clearing my local storage, but this should not be a necessary step.

To Reproduce Steps to reproduce the behavior:

  1. Create the following datamodel:
    type User {
    id: ID! @id
    name: String!
    }
  2. Deploy the datamodel (with --force to allow data loss)
  3. Visit the Prisma Admin UI, and create a User object.
  4. Update the datamodel to the following:
    type User {
    id: ID! @id
    firstName: String
    lastName: String
    }
  5. Deploy again (ie. migrate)
  6. Visit Prisma admin UI again and you should see the error:
    [
    {
    "message": "Cannot query field 'name' on type 'User'. (line 7, column 5):\n    name\n    ^",
    "locations": [
      {
        "line": 7,
        "column": 5
      }
    ]
    }
    ]

Expected behavior The UI should reflect the updated datamodel, and not throw the error above.

Versions (please complete the following information):

Additional context The cached data can be found in local storage by running in a browser console:

const prismaAdmin = JSON.parse(localStorage.getItem('prisma-admin'));
const userModel = prismaAdmin.workspace.projects.<replace with project ID>.queryConfig.User;
console.log(userModel);

cc @kainolophobia

sdnts commented 5 years ago

@thecodeboss I've been able to see this as well. If I understand correctly, this isn't necessarily the datamodel being cached (Since we don't actually save the datamodel anywhere), but the saved queries not being updated when the datamodel changes.

This is something that we've been giving a lot of thought to, and I'll let you know here when we make progress. In the time being, I think just changing the open query to remove (invalid) fields should fix this, as I'm sure you've figured out.

thecodeboss commented 5 years ago

In the time being, I think just changing the open query to remove (invalid) fields should fix this, as I'm sure you've figured out.

The bug does not occur when I'm executing a query; just when I click on the User table itself in the admin UI. I don't know how to edit the default generated queries for tables.

sdnts commented 5 years ago

@thecodeboss Sorry for the late reply! Those tables you see on the left are actually pre-built queries. If you click on the little arrow to the right of the type name (screenshot attached), the query editor should show up and you'll be able to remove the extra fields that cause this issue. Please let me know if that does not work either!

Screenshot 2019-05-08 at 10 56 51
thecodeboss commented 5 years ago

@madebysid Ah I never noticed that arrow before, that's super helpful. Thanks!

IanSaucy commented 4 years ago

Figured I'd chime in to say that I've seen the same issue as well. Seems to happen on both Chrome and Firefox, clearing the cache/cookies fixes it every time.

Environments: Windows 10 + Mac Mojave Firefox + Chrome Prisma 1.34.0

petermijkje commented 4 years ago

I actually just ran into this problem as well and as @IanSaucy stated, when I cleared the cache/ cookies I was able to fix the issue.

Environments: Mac Mojave Chrome Prisma 1.34.10

dcsw commented 4 years ago

On a Mac in Chromium, I found that I could refresh prisma admin by running the following in the browser's devtool's console:

localStorage.setItem('prisma-admin', null)
ar-to commented 4 years ago

@dcsw that works for me but this should really be a button on the UI or actually just part of the deploy command.

EliasTouil commented 4 years ago

Same Issue, solved by clearing cache.