Coder Social home page Coder Social logo

Comments (9)

hayes avatar hayes commented on July 17, 2024 1

This has been release, so many of the empty options objects are no-longer required.

from pothos.

hayes avatar hayes commented on July 17, 2024

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.

hayes avatar hayes commented on July 17, 2024

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...

https://www.typescriptlang.org/play?ts=4.3.2#code/C4TwDgpgBAggTgcwBIQDaTgHgCpQgD2AgDsATAZygFdiBrYgewHdiBtAXQD4oBeKDvIRIUo2ALAAoKNKgB+KAG8AvoKJlK2VgAZ2kmfrmi9B6QC5+AOQbELVVKgCGAI1QQc2rrqkzzuAmpFWAEtiADMIOCgAMSC4cmAAGigAOlSQ8MiAJQh4rxNpeVYYuMSU1PhkNAxMbPjOPPzfSUlQmgBjYCDrKCJ4gApU5IdEcnMKlHQIzFYHc2IqAFsnCKSnWXNlLgBKRSUW9s7u3uAAJgHU4YRR2EQJ6pm5xeW4VfXFNseliKVt3eaJY59ACMJwAzFtJMcziDQUkFFAPlAYVAlBCJAB6dFQAACwHIAFoCJAOoS4HAGHBITlTsCwVsgA

from pothos.

hayes avatar hayes commented on July 17, 2024

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.

hayes avatar hayes commented on July 17, 2024

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

https://www.typescriptlang.org/play?ts=4.3.2#code/C4TwDgpgBAMghgZ2ASQHYBMIA8A8AVKbYCDBKAV1QGtUB7Ad1QG0BdAPigF4oCiT0yTSjQaoANFAB00gJaoAZhABOUAKosoAfjVMA5ABsSAc2AALXRoBcUAAwBYAFChIUAIJKjACQj7IS-IRYxKQU1HSMrBzclJjychDogcECPEzwSGiYuHhsGpqOUIVQAN4Avkn8ZHhpiCgY2Pi5WjxQ1sVQTADSUHJQVBAgtPI8LAC0mtYAcrSok+T6+nAARob4XexQ5dZ4BUV7jvKUAMbAMjNQxEgAFNKScB4I1u5ePn44THDWqOQAtkvKEiWExKpXYAEoQQdjqdzpdgAAmG7Se5GR5uDzeXzKd6fKDfP4AqBAtpHL6-f5KUFsCFlRyOOFXACM8IAzGD6RAkIjmSyJO1SVAeZt2Q4APSiqAAAWACFG2EgJzlSiUtCUHK5TNZYKAA

from pothos.

mmahalwy avatar mmahalwy commented on July 17, 2024

oh man, this is really testing my TS knowledge @hayes :D Is the goal here to get it to work with Schemashape?

from pothos.

hayes avatar hayes commented on July 17, 2024

@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.

Screen Shot 2021-06-03 at 11 38 55 AM

Screen Shot 2021-06-03 at 11 39 11 AM

from pothos.

hayes avatar hayes commented on July 17, 2024

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.

mmahalwy avatar mmahalwy commented on July 17, 2024

Woot! Congrats!

from pothos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.