Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

fix typescript usage #862

Merged
merged 5 commits into from
Jul 18, 2017
Merged

fix typescript usage #862

merged 5 commits into from
Jul 18, 2017

Conversation

jbaxleyiii
Copy link
Contributor

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

@mention-bot
Copy link

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

@jbaxleyiii jbaxleyiii self-assigned this Jul 18, 2017
@apollo-cla
Copy link

apollo-cla 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

@jbaxleyiii jbaxleyiii merged commit 8ee56e9 into master Jul 18, 2017
@jbaxleyiii jbaxleyiii deleted the typescript-1.4.4 branch July 18, 2017 01:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants