-
Notifications
You must be signed in to change notification settings - Fork 787
Added variables types with Typescript #997
Added variables types with Typescript #997
Conversation
@TiuSh: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/ |
@TiuSh This is a great addition! Thank you! I'll figure out what is going on with the CI and merge it in! Congrats on your first contribution here! |
@TiuSh can you rebase this on master? |
27770ec
to
f171298
Compare
Awesome pr, just thought about it too, cant wait 👍 |
f171298
to
6494d28
Compare
@jbaxleyiii I rebased my code on master, and even added a changelog but the build is still failing... |
@TiuSh is it possible to make For example: query allPosts($first: Int!, $skip: Int!) {
allPosts(orderBy: createdAt_DESC, first: $first, skip: $skip) {
id
title
votes
createdAt
}
_allPostsMeta {
count
}
} and typings generated for it with apollo-codegen
what I want is to make use of allPostsQueryVariables import { graphql } from 'react-apollo'
import { allPostsQuery, allPostsQueryVariables } from '~/schema'
import allPostsGql from './allPosts.gql'
const POSTS_PER_PAGE = 10
const withData = graphql<allPostsQuery>(allPostsGql, {
options: {
variables: {
first: POSTS_PER_PAGE,
skip: '0', // must throw error, cause skip is number
},
},
})
export default withData |
Yes, it would be a little cumbersome, but I think it should be possible to type it a little more, so you could do something like : import { graphql, ChildProps } from 'react-apollo'
import { allPostsQuery, allPostsQueryVariables } from '~/schema'
import allPostsGql from './allPosts.gql'
const POSTS_PER_PAGE = 10
type myProps = {};
const withData = graphql<allPostsQuery, myProps, ChildProps<myProps, allPostsQuery>, allPostsQueryVariables>(allPostsGql, {
options: {
variables: {
first: POSTS_PER_PAGE,
skip: '0', // will throw error, cause skip is number
},
},
})
export default withData I'll take a look if i can add it to this PR ! |
@TiuSh yep, it would be awesome for now using this workaround import { graphql, QueryProps } from 'react-apollo'
import { AllPostsQuery } from '~/graphql'
import { mergeProps } from '~/utils/ramda-ext'
import allPostsGql from './allPosts.graphql'
export type Response = AllPostsQuery.Result
export type WrappedProps = Response & QueryProps
export type InputProps = {}
const POSTS_PER_PAGE = 10
const variables: AllPostsQuery.Variables = {
skip: 0,
first: POSTS_PER_PAGE,
}
const withData = graphql<Response, InputProps, WrappedProps>(allPostsGql, {
options: { variables },
props: mergeProps(['data']),
})
export const withApollo = withData |
@TiuSh I'm so excited about this! Thank you! I'll see if I can figure out what is up the CI and get this released |
This reverts commit edaacf9.
This reverts commit edaacf9.
Bad that TVariables cant be configured in graphql method (its related to this comment) P.S. revert was accidental) |
Hey @jbaxleyiii thank your for the merge ! And sorry @BjornMelgaard, I was in vacations, I couldn't make the change in this pull request... But I'll try to create another pr with this update. |
Here is a small update on Typescript part, so we can type queries' & mutations' variables, as apollo-codegen generates these types for us. Default values are used, so it shouldn't break any previous code.
I also added some tests to describe general usage.