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

fix typescript usage #862

Merged
merged 5 commits into from Jul 18, 2017

Conversation

Projects
None yet
3 participants
@jbaxleyiii
Copy link
Member

jbaxleyiii commented Jul 18, 2017

fixes #786
fixes #809,
fixes #810.

Special thanks to @alexzielenski for the comment which helped to inform some of these fixes.

Official usage docs will be coming soon, but in the meantime, here is a sample of how to use some of the improved types:

import * as React from 'react';
import gql from 'graphql-tag';

import { graphql } from '../src';
import { ChildProps, NamedProps, QueryProps } from '../src/types';

const historyQuery = gql`
  query history($solutionId: String) {
    history(solutionId: $solutionId) {
      solutionId
      delta
    }
  }
`;

type Data = {
  history: Record<any, any>[];
};

type Props = {
  solutionId: string;
};

// standard wrapping
const withHistory = graphql<Data, Props>(historyQuery, {
  options: ownProps => ({
    variables: {
      solutionId: ownProps.solutionId,
    },
  }),
});

class HistoryView extends React.Component<ChildProps<Props, Data>, {}> {}

const HistoryViewWithData = withHistory(HistoryView);

// decorator
@graphql<Data, Props>(historyQuery)
class DecoratedHistoryView extends React.Component<ChildProps<Props, Data>> {
  render() {
    return null;
  }
}

// with using name
const withHistoryUsingName = graphql<Data, Props>(historyQuery, {
  name: 'organisationData',
  props: ({
    organisationData,
  }: NamedProps<{ organisationData: QueryProps & Data }, Props>) => ({
    ...organisationData,
  }),
});

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

James Baxley added some commits Jul 18, 2017

James Baxley
James Baxley
@mention-bot

This comment has been minimized.

Copy link

mention-bot commented Jul 18, 2017

@jbaxleyiii, thanks for your PR! By analyzing the history of the files in this pull request, we identified @calebmer, @tmeasday and @brettjurgens to be potential reviewers.

James Baxley added some commits Jul 18, 2017

@jbaxleyiii jbaxleyiii self-assigned this Jul 18, 2017

@meteor-bot

This comment has been minimized.

Copy link

meteor-bot commented Jul 18, 2017

Warnings
⚠️

There are library changes, but not tests. That's OK as long as you're refactoring existing code

Generated by 🚫 dangerJS

James Baxley

@jbaxleyiii jbaxleyiii merged commit 8ee56e9 into master Jul 18, 2017

6 checks passed

CLA Author has signed the Meteor CLA.
Details
Danger ⚠️ Danger found some issues. Don't worry, everything is fixable.
Details
bundlesize ./dist/index.min.js: 11.62kB < threshold 20kB gzip (69B larger than master, careful!)
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
coverage/coveralls Coverage remained the same at 91.401%
Details

@jbaxleyiii jbaxleyiii deleted the typescript-1.4.4 branch Jul 18, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment