Skip to content

[@types/graphql] Add generic type on ExecutionResult#26763

Merged
mhegazy merged 3 commits intoDefinitelyTyped:masterfrom
clayne11:add-fetch-result-generic
Jul 3, 2018
Merged

[@types/graphql] Add generic type on ExecutionResult#26763
mhegazy merged 3 commits intoDefinitelyTyped:masterfrom
clayne11:add-fetch-result-generic

Conversation

@clayne11
Copy link
Copy Markdown
Contributor

Without a generic type on ExecutionResult we can't have typesafe
operations.

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: <>
  • Increase the version number in the header if appropriate.
  • If you are making substantial changes, consider adding a tslint.json containing { "extends": "dtslint/dt.json" }.

@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Jun 22, 2018

@clayne11 Thank you for submitting this PR!

🔔 @TonyPythoneer @calebmer @intellix @firede @kepennar @freiksenet @IvanGoncharov @DxCx @rportugal @tgriesser @dyst5422 @adnsio @divyenduz @bradzacher - please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead.

@typescript-bot typescript-bot added Popular package This PR affects a popular package (as counted by NPM download counts). Awaiting reviewer feedback labels Jun 22, 2018
@firede
Copy link
Copy Markdown
Contributor

firede commented Jun 24, 2018

IMHO, as the definition of graphql, @types/graphql should follow graphql.
If there is a breaking change, you should probably send them a pull request first.

@clayne11
Copy link
Copy Markdown
Contributor Author

clayne11 commented Jun 24, 2018

All this does is add a generic type. I can default it back to the previous definition if you prefer?

export interface ExecutionResult<TData = { [key: string]: any };> {
    errors?: ReadonlyArray<GraphQLError>;
    data?: Readonly<TData>;
}

Would you prefer that? Then there's effectively no change but we have the ability to add a generic.

@IvanGoncharov
Copy link
Copy Markdown
Contributor

@clayne11 I agree with @firede we shouldn't deviate from graphql-js.
Can you please open PR against graphql-js:
https://github.com/graphql/graphql-js/blob/master/src/execution/execute.js#L115

Copy link
Copy Markdown
Contributor

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably add a default generic value to all of these new definitions so that there is no risk of this being a breaking change.

Comment thread types/graphql/execution/execute.d.ts Outdated
export interface ExecutionResult<TData> {
errors?: ReadonlyArray<GraphQLError>;
data?: { [key: string]: any };
data?: Readonly<TData>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readonly will probably cause some bugs for people attempting to consume + transform the data after execution.

Probably just make it TData here instead to reduce the risk of a breaking change.

@typescript-bot typescript-bot added Revision needed This PR needs code changes before it can be merged. and removed Awaiting reviewer feedback labels Jun 24, 2018
@typescript-bot
Copy link
Copy Markdown
Contributor

@clayne11 One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits or comments. Thank you!

@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Jun 25, 2018
Without a generic type on ExecutionResult we can't have typesafe
operations.
@clayne11 clayne11 force-pushed the add-fetch-result-generic branch from a822ba3 to 46ffe35 Compare June 26, 2018 13:38
@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Jun 26, 2018
@typescript-bot
Copy link
Copy Markdown
Contributor

🔔 @bradzacher - Thanks for your review of this PR! Can you please look at the new code and update your review status if appropriate?

@typescript-bot typescript-bot added Revision needed This PR needs code changes before it can be merged. Popular package This PR affects a popular package (as counted by NPM download counts). and removed Popular package This PR affects a popular package (as counted by NPM download counts). labels Jun 26, 2018
@mhegazy mhegazy merged commit deb7d8b into DefinitelyTyped:master Jul 3, 2018
IvanGoncharov added a commit to IvanGoncharov/graphql-js that referenced this pull request Mar 18, 2020
Reverts DefinitelyTyped/DefinitelyTyped#26763
Since we can't gurantee that response match types it was basically
glorified type cast.
IvanGoncharov added a commit to graphql/graphql-js that referenced this pull request Mar 18, 2020
Reverts DefinitelyTyped/DefinitelyTyped#26763
Since we can't gurantee that response match types it was basically
glorified type cast.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Popular package This PR affects a popular package (as counted by NPM download counts). Revision needed This PR needs code changes before it can be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants