Skip to content

Instantly share code, notes, and snippets.

@andsens
Created April 18, 2020 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andsens/2407142407bb9d3732bac0cf0ed8410b to your computer and use it in GitHub Desktop.
Save andsens/2407142407bb9d3732bac0cf0ed8410b to your computer and use it in GitHub Desktop.
FragmentReference reproduce for relay-tools/relay-compiler-language-typescript
import { ComponentPaginationQuery } from "./artifacts/ComponentPaginationQuery.graphql";
import { Component_items$key } from "./artifacts/Component_items.graphql";
export function Component(props: { itemsFragment: Component_items$key }) {
const {
data: { items },
} = usePaginationFragment<ComponentPaginationQuery, Component_items$key>(
graphql`
fragment Component_items on Viewer
@argumentDefinitions(
count: { type: "Int", defaultValue: 10 }
cursor: { type: "String" }
)
@refetchable(queryName: "ComponentPaginationQuery") {
items(first: $count, after: $cursor)
@connection(key: "ComponentEdge_items", filters: []) {
edges {
node {
id
}
}
}
}
`,
props.itemsFragment
);
return <div />;
}
{
"scripts": {
"compile": "relay-compiler --language typescript --artifactDirectory artifacts --src . --schema schema.graphql"
},
"dependencies": {
"graphql": "^15.0.0",
"relay-compiler": "^9.0.0",
"relay-compiler-language-typescript": "^12.0.0",
"typescript": "^3.8.3"
}
}
type Query {
viewer: Viewer!
}
interface Node {
id: ID!
}
type Viewer implements Node {
id: ID!
items(after: String, first: Int, before: String, last: Int): ItemConnection!
}
type ItemConnection {
pageInfo: PageInfo!
edges: [ItemEdge]
}
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}
type ItemEdge {
node: Item
cursor: String!
}
type Item implements Node {
id: ID!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment