plugin-graphql icon indicating copy to clipboard operation
plugin-graphql copied to clipboard

Support for Hasura-styled query?

Open stevefan1999-personal opened this issue 4 years ago • 7 comments

Hasura has their own style of writing queries: https://hasura.io/docs/1.0/graphql/manual/queries/query-filters.html

Here's an example adapter to adapt some compatibility with Hasura:

export class CustomAdapter extends DefaultAdapter {
  public getRootMutationName: () => string = () => 'mutation_root'
  
  public getRootQueryName: () => string = () => 'query_root'
  
  public getConnectionMode (): ConnectionMode {
    return ConnectionMode.PLAIN
  }
  
  public getArgumentMode (): ArgumentMode {
    return ArgumentMode.TYPE
  }
  
  public getNameForFetch (model: Model, plural: boolean): string {
    return model.singularName
  }
  
  public prepareSchemaTypeName (name: string): string {
    return name
  }
}

However, since the filter name cannot be changed (fixed to be "where"), I wonder if we can change it from the plugin -- Let's add more adapter transforms for that.

stevefan1999-personal avatar May 17 '20 11:05 stevefan1999-personal

Would it be enough to allow to overwrite the filter name from filter to where? When you want, you can create a PullRequest for that :)

phortx avatar May 22 '20 09:05 phortx

Hasura style querying would be absolutely amazing. I'm just scrolling through the code to see what would need changing and it's definitely more than just renaming "filter" to "where"..

For example in Hasura you write where: {name: {_eq: "Sidney"}} while in this project you would write find: {name: "Sidney"}

Also Hasura allows for really powerful filtering techniques that would probably require a major change to the query builder used in this project.

Still I think that the integration of this project with VuexORM is really nice. I am thinking about using this as a way to "mirror" a backend database so that the app can use the VuexORM query methods to work on local data instead of doing API calls all the time. This wouldn't require super complex GraphQL queries (just simple CRUD on entities), so I think it should be fine. Thanks for the great work on this @phortx !

philon123 avatar Jun 30 '20 22:06 philon123

Yes, that kind of filtering would take some bigger changes, I think.

But maybe we can try to support the basics. I would be really happy to see a MergeRequest for an adapter :)

phortx avatar Jul 01 '20 05:07 phortx

I am checking out lots of similar projects to this one, but keep coming back, hoping that I'l find the strength to fix the integration issues with Hasura :)) For info, some more important Hasura specific formats:

Querying a single entity by primary key looks like this:

{
  user_by_pk(id: "1c217e3a-ebf2-4e90-ab48-03474912afed") {
    id
    username
  }
}

or like this, but then the result is an array with just one entry:

{
  user(where: {id: {_eq: "1c217e3a-ebf2-4e90-ab48-03474912afed"}}, limit: 1) {
    id
    username
    evil_rate
  }
}

Getting all entries, in this case all users via User.fetch(), works fine when using the Adapter stevefan posted in OP!

philon123 avatar Jul 04 '20 12:07 philon123

Hey @stevefan1999-personal I see your (unmerged) commits from last summer, how did you end up with this? Is your branch working well enough for simple CRUD? Or did you give up? :)

philon123 avatar Mar 17 '21 21:03 philon123

Hey @stevefan1999-personal I see your (unmerged) commits from last summer, how did you end up with this? Is your branch working well enough for simple CRUD?

Or did you give up? :)

somewhat, i had to schedule my time for school and various other personal time too

stevefan1999-personal avatar Mar 17 '21 23:03 stevefan1999-personal

use:

getNameForFetch(model, plural ){ if (plural) return model.pluralName else return model.singularName }

Lizabettamur avatar Nov 05 '22 22:11 Lizabettamur