Comments (9)
This has been release, so many of the empty options objects are no-longer required.
from pothos.
This is a design choice. GiraphQL was designed around the need for tightly coupled plugins that can add options almost anywhere. The side effect of this is that any object may end up with required options based on new plugins (we did this with PII annotations at Airbnb).
I hope I can find a good solution for this eventually, but I haven't found a good pattern to detect if an arg is an options object with no required fields and automatically make it optional.
I have a few ideas, but haven't had time to try them out and see if they result in a decent user experience.
from pothos.
I think something along the lines the following might work. This isn't quite good enough yet, since it replaces arg names with arg_1, arg_2, etc...
from pothos.
Could probably get it working with correct arg names by hard coding a few cases rather than trying to make it work "properly"
from pothos.
This seems to work, as long as the empty options object is the only optional arg (which is the case for most of GiraphQL), I have an idea for a couple of the places this wouldn't work).
from pothos.
oh man, this is really testing my TS knowledge @hayes :D Is the goal here to get it to work with Schema
shape?
from pothos.
@mmahalwy So the issue is that if you have a method like t.exposeID('id', {})
that second arg (options) seems redundant and SHOULDN'T be required. The problem with that is that some (theoretical) plugin could add a REQUIRED prop to that options object (we did this at airbnb with PII levels) so now if that arg was optional, you would be missing an option that is required. Using the above trick, you can define args that depending on the shape of options object will automatically make the options are required only if it has any properties that are also required.
Not sure if that makes sense, but the end result would be that for a little bit of trickery, you now can remove all the empty options objects but still have them automatically become required if some plugin adds required options.
The cool part is that because of the way the types are structured, if you hover over the functions definitions, you see just the expected arg types, and the the helper types disappear, and the arg names are preserved in the tooltip.
from pothos.
this would be implemented something like: https://github.com/hayes/giraphql/pull/79/files
so you can do t.expose('id')
rather than t.expose('id', {})
. That PR is probably a LONG way from being ready, need to do some testing to see how much it affects things.
from pothos.
Woot! Congrats!
from pothos.
Related Issues (20)
- Getting a weird Typescript error with Prisma plugin HOT 3
- Idea: a guide for incremental adoption of pothos in a nexus/typegraphql project HOT 1
- loadableObject doesn't infer type properly HOT 3
- Support Client Directives in Prisma plugin HOT 3
- Nextjs Error webpack : TypeError: _builder__WEBPACK_IMPORTED_MODULE_1__.builder.prismaObject HOT 2
- Can we use `graphql-scalars` scalars? HOT 10
- how to use edge as output field in relay mutation HOT 6
- [Question] Is there any way to add the prisma types with non prisma types to builder.ObjectType HOT 1
- Prisma Plugin - How to expose "decimal" or other DB types? HOT 4
- Can't use objectType with a generic class HOT 3
- Hardcoded path does not exist HOT 2
- [bug] Pothos Subscriptions with Apollo v4 HOT 2
- `relationCount` errors. on null returned for non-nullable field HOT 3
- Feat: [GraphQL Yoga] Request for access to edge environmental values (Cloudflare KV Namespaces, Vercel Edge Config, etc) HOT 2
- Change the Next.js example to use Yoga? HOT 1
- Trying to pass Options to errorOptions on the Error plugin for Pothos but getting error ``` TypeError: Ref ({ parentTypeName , fieldName })=>`${parentTypeName}${fieldName}` has not been implemented``` when trying to generate schema. HOT 3
- `resolveArrayConnection` returns nullable `ConnectionShape` HOT 2
- Type errors on nullable in Typescript 4.9 HOT 6
- Integrating Apollo cacheControl feature into schema not easily possible HOT 2
- Outdated docs for Sentry envelop usage HOT 2
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 pothos.