Closed Tritpi closed 6 years ago
Yes
5
Và o 16-11-2017 14:04, "Tritpi" notifications@github.com đã viết:
Is there a way to customize the GraphQL generated schema so that the way in which the tables can be accessed can be changed. Currently, in the GraphiQL interface the table names of tables in the underlying Postgres DB get the word 'all' prefixed. Can this be customized such that the user gets to access the table name exactly the way it is in the DB. Also, can the schema be modified such that the nodes,edges,totalcount etc. can be taken off or renamed.
We are aware that the auto-export feature can be used to export the GraphQL generated schema locally. But how can this be used to tweak the schema or customize it according to our requirements.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/postgraphql/postgraphql/issues/626, or mute the thread https://github.com/notifications/unsubscribe-auth/AfZ33C6fPxdYibwD0O1ueuDnQO1f0Rffks5s295hgaJpZM4QgDAu .
Can you please elaborate on how this can be done with an example.
Check out the inflector in v4:
https://github.com/postgraphql/postgraphql/pull/506#issuecomment-328831456
For the other fields check out our extending docs:
ran into this issue also. It just seems too opinionated...
particularly when you have a table like
plan_index
and the generated query for it is allPlanIndices
That's certainly human, but it's a road block for dynamic table creation. the prefix all is ok, but why do you need to change the plurals? and further, why change such an oddball plural?
I think the appropriate solution would be to create aliases.
At the moment you can override the inflector if you don’t like its defaults. In future you’ll be able to specify per-table overrides using smart comments.
I'm running it inside a container, so it's easier to just look at what the default dependencies are than try to override anything. luckily, i'm building the frontend in javascript, so it's not difficult.
You can provide custom inflectors quite easily in v4. In this case we can override the allRows
method to trim the all-
prefix:
MyInflectorPlugin.js:
const { makeAddInflectorsPlugin } = require('graphile-utils');
module.exports = makeAddInflectorsPlugin({
allRows(table: PgClass) {
return this.camelCase(
// Was: `all-${this.pluralize(this._singularizedTableName(table))}`
// Now:
this.pluralize(this._singularizedTableName(table))
);
},
});
Then --append-plugins `pwd`/MyInflectorPlugin.js
The built in PG inflectors are defined in makeNewBuild
and PgBasicsPlugin
; you can overwrite any that you want. Be sure to not use arrow functions otherwise you'll override this
and lose access to the other inflectors.
Note also that smart comment renaming is now available: https://www.graphile.org/postgraphile/smart-comments/#renaming
Is there a way to customize the GraphQL generated schema so that the way in which the tables can be accessed can be changed. Currently, in the GraphiQL interface the table names of tables in the underlying Postgres DB get the word 'all' prefixed. Can this be customized such that the user gets to access the table name exactly the way it is in the DB. Also, can the schema be modified such that the nodes,edges,totalcount etc. can be taken off or renamed.
We are aware that the auto-export feature can be used to export the GraphQL generated schema locally. But how can this be used to tweak the schema or customize it according to our requirements.