add readInlineData (#38462)

* add readInlineData

* Update index.d.ts

* add tests

* fix

* lint

* add fragment as example
This commit is contained in:
Giacomo Tagliabue 2019-09-23 05:36:14 -04:00 committed by Eloy Durán
parent d948328df3
commit b5dcab9278
2 changed files with 38 additions and 11 deletions

View File

@ -140,6 +140,11 @@ interface ConnectionData {
pageInfo?: Partial<PageInfo> | null;
}
export function readInlineData<T extends _RefType<any>>(
fragment: GraphQLTaggedNode,
ref: FragmentOrRegularProp<T>,
): T;
type FragmentVariablesGetter = (prevVars: Variables, totalCount: number) => Variables;
export interface ConnectionConfig<Props = object> {

View File

@ -5,17 +5,19 @@ import * as React from 'react';
import { Environment, Network, RecordSource, Store, ConnectionHandler } from 'relay-runtime';
import {
graphql,
commitMutation,
createFragmentContainer,
createPaginationContainer,
createRefetchContainer,
requestSubscription,
QueryRenderer,
ReactRelayContext,
RelayRefetchProp,
RelayPaginationProp,
RelayProp,
commitMutation,
createFragmentContainer,
createPaginationContainer,
createRefetchContainer,
FragmentOrRegularProp,
graphql,
QueryRenderer,
ReactRelayContext,
readInlineData,
RelayPaginationProp,
RelayProp,
RelayRefetchProp,
requestSubscription,
} from 'react-relay';
// ~~~~~~~~~~~~~~~~~~~~~
@ -594,6 +596,26 @@ function markNotificationAsRead(source: string, storyID: string) {
});
}
// ~~~~~~~~~~~~~~~~~~~~~
// readInlineData
// ~~~~~~~~~~~~~~~~~~~~~
const storyFragment = graphql`
fragment Story_story on Todo {
id
text
isPublished
}
`;
function functionWithInline(
storyRef: FragmentOrRegularProp<Story_story>,
): Story_story {
return readInlineData<Story_story>(storyFragment, storyRef);
}
functionWithInline({ ' $fragmentRefs': _Story_story$ref });
// ~~~~~~~~~~~~~~~~~~~~~
// Modern Subscriptions
// ~~~~~~~~~~~~~~~~~~~~~