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

Support for Hasura-styled query? #147

Open
stevefan1999-personal opened this issue May 17, 2020 · 7 comments
Open

Support for Hasura-styled query? #147

stevefan1999-personal opened this issue May 17, 2020 · 7 comments

Comments

@stevefan1999-personal
Copy link
Contributor

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.

@phortx
Copy link
Collaborator

phortx commented May 22, 2020

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 :)

@philon123
Copy link

philon123 commented Jun 30, 2020

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 !

@phortx
Copy link
Collaborator

phortx commented Jul 1, 2020

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 :)

@philon123
Copy link

philon123 commented Jul 4, 2020

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
Copy link

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? :)

@stevefan1999-personal
Copy link
Contributor Author

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

@Lizabettamur
Copy link

use:

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

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

No branches or pull requests

4 participants