GithubHelp home page GithubHelp logo

Typescript types about storefront-api-examples HOT 6 OPEN

shopify avatar shopify commented on May 22, 2024
Typescript types

from storefront-api-examples.

Comments (6)

cjkihl avatar cjkihl commented on May 22, 2024 9

@swalkinshaw and @yoDon If this is still interesting, I created a package that includes all Typescript typings for Shopify Storefront API.
All typings and comments are auto-generated from the GraphQL schema version: 2020-01.
Contributions are welcome. 😊
https://github.com/caki0915/shopify-storefront-api-typings
https://www.npmjs.com/package/shopify-storefront-api-typings

from storefront-api-examples.

Amerr avatar Amerr commented on May 22, 2024 6

Wow its been 2 years but the quest remains the same, its not easy to find a shopify admin api in typescript

from storefront-api-examples.

yoDon avatar yoDon commented on May 22, 2024 4

Just checking if Shopify has moved towards typescript in the past six months

from storefront-api-examples.

swalkinshaw avatar swalkinshaw commented on May 22, 2024

Are you referring to https://github.com/Shopify/storefront-api-examples/blob/master/angular-graphql-client/src/app/shared/services/types.ts?

The Angular example was an external contribution unfortunately. I don't know how the contributor generated it originally. I imagine (and hope) it was automated somehow though!

from storefront-api-examples.

yoDon avatar yoDon commented on May 22, 2024

@swalkinshaw the types.ts file you mentioned still just has the GraphQL text descriptors (with types.ts probably hand-made by a contributor from the original types.js file which I'm guessing was procedurally generated by someone at Shopify). These files are soooo close to what is needed for strongly-typed access to the data, but it's just exactly not usable for that today. What we need are either class or interface descriptions like

interface ICheckout {
  appliedGiftCards:IAppliedGiftCard;
  availableShippingRates:IAvailableShippingRates,
  ...

where what the types.js/types.ts files contain are string-based lines like

const Checkout = {
  "name": "Checkout",
  "kind": "OBJECT",
  "fieldBaseTypes": {
    "appliedGiftCards": "AppliedGiftCard",
    "availableShippingRates": "AvailableShippingRates",
  ...

The content is incredibly close, just some minor grepping and editing to convert. The problem is there is some shopify-generated magic in the types.js/types.ts text that I can't figure out what to do with, for example all of the "OBJECT" type descriptors contain lines like "implementsNode": true or "implementsNode": false but I'm not seeing any definition in the file of what implentsNode means which makes me think this file came from inside Shopify (presumably implementsNode is describing some base class or interface that the individual concrete classes should extend, but I don't know what that base should contain).

Given that GraphQL is at the core a strongly-typed API, and given that you're a tiny, tiny bit of search-and-replace from having your interface fully typed, it would be a huge help to all of us that do use typescript if you folks could do that tiny last step and publish this file as an actual types.d.ts file, since its soooo close to being one already.

from storefront-api-examples.

swalkinshaw avatar swalkinshaw commented on May 22, 2024

This is probably something we'd have to automate in another repository. I personally don't have any experience with TS. Are there existing tools to generate the types from a GraphQL API? Seems like something should exist since that's a benefit that a spec like GraphQL provides.

from storefront-api-examples.

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.