Comments (14)
This same thing happened to me, @paulbjensen, for me it was a query like:
{
snapshots {name,id}
}
And I would only get one record at a time.
What fixed it for me was doing instead:
{
snapshotss {name, id}
}
It looks strange, but adding the "s" cleared things up right away. Categories also ends in "s", maybe try "categoriess" instead.
from objection-graphql.
@PatrickBeamECR thanks for the tip. I will give it a try in a bit, and try and dig into what is happening there.
from objection-graphql.
So work project ate my homework, but I've checked this now, and can confirm that putting an extra s on the end returns the records, so it looks like a bug with pluralization.
Thank you so much for finding this, I would never have discovered it and just assumed that I was doing something wrong. I will dig into the code a bit more into the source code and see whats going in.
from objection-graphql.
Of course! I found it completely by accident trying to figure the same thing out--held down the 's' a bit too long and ran it. Best of luck to you.
from objection-graphql.
Here's the bit of code that appends the s on the end:
https://github.com/Vincit/objection-graphql/blob/master/lib/SchemaBuilder.js#L119
Going to keep digging around to understand the context around singleFieldName and listFieldName, as I wasn't aware of this distinction.
from objection-graphql.
I'd like to propose this change.
Given a model with a modelClass value of Category
, the singleFieldName
value should be 'category', and the listFieldName
value should be 'categories'.
I will fork the repo and make the change there, and then submit a PR if it's working fine and there's no objection to the idea (I love a good pun).
from objection-graphql.
Actually, I explored the code a bit more and realised that passing some additional options to the model builder worked fine:
const graphQlSchema = graphQlBuilder()
.model(Category, { fieldName: 'category', listFieldName: 'categories' })
.build();
One issue that remains though is that although the single field result is one item, the database query is still making a request for all of the records in the database table. Ideally we'd want to pass a LIMIT 1 to the database query if returning a single record to the result
from objection-graphql.
I scanned the code a bit more and realised that 'limit' and 'offset' options were used for the 'range' query argument's function, but had no separate implementations, so I've added them in this PR:
There is one lingering question that remains. When requesting a single object for a type, would it make sense for limit: 1 to be applied to this, as it would stop us making a request that fetches all of the records in the database table and returns the first, and actually tells the DB to return 1 record.
from objection-graphql.
Hi @paulbjensen , thanks for the PR. I agree, that the default pluralization rules here are primitive and adding 's' to the end of the word doesn't make sense for many cases. I'll think how to make it work for more cases out of the box and maybe utilize some external libraries that solve this problem like pluralize. Regarding the #45, I see that many changes are just formatting. Did you use npm run lint:js
before commit?
from objection-graphql.
Hi @nasushkov, I didn't. Apologies, my text editor had Prettier enabled, but it didn't pick up rules on formatting tabs/spaces in the .eslintrc file.
I will make those tweaks to the PR to remove the formatting changes, and potentially make a new PR with just the required changes.
As for the way to apply singular/plural naming of the modelClass in the library, it was possible to do it with tweaking the combination of the _.camelCase and utils.typeNameForModel to achieve the desired singular/plural combinations. I will find that code in a bit.
from objection-graphql.
I'm going to close the PR for #45 and make a fresh PR that doesn't contain extra formatting.
from objection-graphql.
Submitted #46
from objection-graphql.
Hi @paulbjensen, sorry for a late response. Could you also add tests to the PR #46?
from objection-graphql.
@nasushkov yes, that's done now.
from objection-graphql.
Related Issues (20)
- Fastify integretation?
- How can I apply order by on two or more columns
- eager is not a function HOT 1
- How to handle jsonSchema relations?
- How to retrieve DB context in a Mutation with `extendWithMutations` HOT 7
- Problems with `build()`, relation class in Models are not being recognized
- Relationship class not being recognized on a Model during `build()` HOT 1
- How to write mutation in Schema Defition Language HOT 3
- Mutation Tests are not passing correctly, the mutation is not actually written to the test DB
- Basic problem with standard Objection express-es6 example and objection-graphql HOT 1
- Support facebook/dataloader in GraphQL schema HOT 1
- extendWithMutations function takes the last mutation passed always HOT 1
- Error: relation type "HasManyRelation" is not supported
- Anyone have a small sample project that implements mutations?
- Relations not loading after mutation HOT 3
- Is there any way to implement resolvers in the jsonSchema?
- Set writeOnly and readOnly jsonSchema's value options HOT 1
- How to implement access control? HOT 2
- How to implement virtual Attributes? HOT 1
- Return empty array instead of null
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from objection-graphql.