Is there any way to enable optional ordering on ne...
# orm-help
s
Is there any way to enable optional ordering on nexus? When I add
ordering: { myField: true }
it makes providing an
orderBy
mandatory instead of optional.
r
@Sascha 👋 Are you adding
ordering
on a CRUD method? If so, I’m not facing this as only the input inside the
orderBy
is mandatory and not
orderBy
itself.
s
Nope, adding this on a objectType.
Copy code
t.model("FormPrototype").items({ type: "Item", pagination: false, ordering: {
      position: true
    } });
Copy code
[GraphQL error]: Message: Field "items" argument "orderBy" of type "[FormPrototypeItemsOrderByInput!]!" is required, but it was not provided., Location: undefined, Path: undefined
r
I’m adding it in this way:
Copy code
t.model.posts({ ordering: { title: true } })
And the resulting type is not required:
Could you try it this way?
s
That's pretty much how I add it, just that I define the prisma model directly as my object is a composite of multiple things.
Copy code
type QuestPrototype {
  ...
  items(orderBy: [FormPrototypeItemsOrderByInput!]!): [Item!]!
  ...
}
Ah, I can actually just add a default sorting on my relation data in the prisma query inside my resolver I guess.
r
I am unable to reproduce this by trying with. a composite as well:
Copy code
const Composite = ns.objectType({
  name: 'Composite',
  definition(t) {
    t.model('User').id()
    t.model('User').posts({ ordering: { title: true } })
  },
})
Resulting GraphQL:
What’s your Prisma and Nexus version?
s
Copy code
"nexus": "^1.0.0",
    "nexus-plugin-prisma": "^0.27.0",
Copy code
"@prisma/client": "2.13.1"
ah, sorry... let me get you the actual installed versions for the former
... ah yeah, it's actually 1.0.0 and 0.27.0
@Ryan which versions are you using if I may ask?
r
I’m using the following:
Copy code
"nexus": "^1.0.0",
"nexus-plugin-prisma": "^0.29.0",
Also Prisma 2.15.0
@Sascha 👋 Was the above issue resolved by updating?
s
@Ryan I solved things differently for now, but I'll check this approach as well. Consider it solved tho 🙂 Thank you and have a wonderful sunday!
🙌 1
💯 1