Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3 roadmap #72

Closed
acro5piano opened this issue Jul 16, 2019 · 12 comments
Closed

v3 roadmap #72

acro5piano opened this issue Jul 16, 2019 · 12 comments
Assignees
Labels
discussion Help your opinion

Comments

@acro5piano
Copy link
Owner

acro5piano commented Jul 16, 2019

I think typed-graphqlify could do more than the current type alias.

While I was working on Apollo and Apollo Codegen instead of typed-graphqlify, I feel it inconvenient in the following points:

  • Importing a lot of code from __generated__ directories
  • Multiple schemas, in terms of microservices
  • No serializer concept

And typed-graphqlify lacks the following features:

And I would like to add a feature, requesting and type inference from query.

Currently we have to write

import { query, types } from 'typed-graphqlify'

const query = {
  users: [{
    id: types.number,
    name: types.string,
  }]
}

export type ReturnTypeOfQuery = typeof query

export const usersQuery = query('GetUsers', query)

// in other file
import { usersQuery, ReturnTypeOfQuery } from './path/to/query'

const res: ReturnTypeOfQuery = (await apolloClient.query(usersQuery)).data

This is bothering, so if we can request like this:

import graphql from 'typed-graphqlify'

graphql.init({ baseUri: '/graphql' })

const res = await graphql({
  query: {
    users: [{
      id: types.number,
      name: types.string,
    }]
  },
  variables: {
    email: '@gmai.com',
  },
})

// and `typeof res` is like this:
interface res {
  users: {
    id: number,
    name: string
  }[],
}

This feature looks too much for this library, so I'm thinking splitting into other library though...

@acro5piano
Copy link
Owner Author

And actually I don't like the syntax of id: types.number as it is different from the original GQL syntax.

I want to do like eventually:

const query = gql`
  query GetUsers {
    user {
      id: ${types.number}
      name: ${types.string}
    }
  }
`

However, the structure is apparently impossible without codegen. So I'm thinking what is the least verbose syntax.

@acro5piano acro5piano added the discussion Help your opinion label Jul 16, 2019
@albertcito
Copy link

Hello @acro5piano I made a small library based in your library. Maybe it's a good idea to add these features to your library (or maybe not XD)

https://github.com/albertcito/typed-graphql-class

@acro5piano
Copy link
Owner Author

Hi @albertcito !
We are still on the way to find the best combination GraphQL + TypeScript. Good luck!!

@acro5piano
Copy link
Owner Author

acro5piano commented Apr 23, 2020

Considering these hacks to omit params:

expect(
  mutation("BulkInsertUsers")({ $objects: "[user_insert_input!]!" })(q => {
    q("insert_users")({ objects: "$objects" })({
      returning: {
        id: q.types.number
      }
    });
  })
).toEqual(gql`
  mutation BulkInsertUsers($objects: [user_insert_input!]!) {
    insert_users(objects: $objects) {
      returning {
        id
      }
    }
  }
`);

expect(
  mutation("BulkInsertUsers")({
    insert_users: {
      returning: {
        id: q.types.number
      }
    }
  })
).toEqual(gql`
  mutation BulkInsertUsers($objects: [user_insert_input!]!) {
    insert_users(objects: $objects) {
      returning {
        id
      }
    }
  }
`);

@bkniffler
Copy link

typed-graphqlify looks very promising. I especially like that it doesn't try to be a client, but only a transformer for queries/mutation.

In terms of querying API, I really liked this one: https://www.npmjs.com/package/graphql-typed-client

As long as there is no code generation involved, it will be hard to allow for proper typing of input params and typed-graphqlify will be just half useful. Looking at projects like Hasura, input params can get very complex themselves and I'd like them to be type safe too.

@acro5piano
Copy link
Owner Author

@bkniffler
Thank you for your opinion.
I agree with you. Proper typing and validation could be good features, whereas client library is too much. Client library should be a separated library.

@fwh1990
Copy link

fwh1990 commented Sep 17, 2020

https://github.com/redux-model/graphql

I'm watching your idea, and feel free to watch mine.

import { types, graphql } from '@redux-model/graphql';

const tpl = graphql.query({
  getUser: {
    id: types.number,                 // number
    name: types.string,               // string
    bankAccount: {                    // object
      id: types.number,
      branch: types.string.number,    // string | number
    },
    logs: types.fn(['page_Int', 'size_Int'], types.array({
      id: types.number,
      title: types.null.undefined.string,  // string | undefined | null
    })),
  }
});

type Response = typeof tpl.type;

const { query, variables } = tpl({
  page_Int: 1,
  size_Int: 10,
});

console.log(query);
// query GetUser ($page: Int, $size: Int) {
//   getUser {
//     id
//     name
//     bankAccount {
//       id
//       branch
//     }
//     logs (page: $page, size: $size) {
//       id
//       title
//     }
//   }
// }

console.log(variables);
// { page: 1, size: 10 }

It's es5 based. No Symbol and Map

@fwh1990
Copy link

fwh1990 commented Sep 17, 2020

By the way, I am using redux model which is base on redux. And I don't like apollo client.

@acro5piano
Copy link
Owner Author

@fwh1990
Thanks for your opinion. Redux Model looks interesting.

@fwh1990
Copy link

fwh1990 commented Sep 17, 2020

@fwh1990
Thanks for your opinion. Redux Model looks interesting.

Yep, its goal is saving people's life. And it will let people know that TS can be coding faster, not slower.

@acro5piano
Copy link
Owner Author

acro5piano commented Oct 17, 2020

I have been missing this syntax. We don't have to use params if we embed it into key.

  mutation('BulkInsertUsers($objects: [user_insert_input!]!)', {
    'insert_users(objects: $objects)': {
      returning: {
        id: types.number
      }
    }
  })
  mutation BulkInsertUsers($objects: [user_insert_input!]!) {
    insert_users(objects: $objects) {
      returning {
        id
      }
    }
  }

This could be enabled by template literal types TS 4.1.

@acro5piano
Copy link
Owner Author

acro5piano commented Nov 3, 2020

v3 is released.

#72

@acro5piano acro5piano self-assigned this Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Help your opinion
Projects
None yet
Development

No branches or pull requests

4 participants