Skip to content

Commit

Permalink
add story with extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislaw Wilczynski authored and Stanislaw Wilczynski committed Oct 18, 2024
1 parent 504d057 commit ad913b3
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/examples/codegen.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
overwrite: true
schema:
- "./src/schema.graphql"
- "./src/clientExtensions.graphql"
generates:
src/__generated__/schema.all.interface.ts:
plugins:
Expand Down
15 changes: 12 additions & 3 deletions packages/examples/relay.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"src": "./src/relay",
"schema": "./src/schema.graphql",
"language": "typescript"
"sources": {
"src/relay": "examples"
},
"projects": {
"examples": {
"language": "typescript",
"schema": "src/schema.graphql",
"schemaExtensions": [
"src/clientExtensions.graphql"
]
}
}
}
18 changes: 18 additions & 0 deletions packages/examples/src/__generated__/schema.all.interface.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions packages/examples/src/clientExtensions.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extend type Query {
clientExtension: String
viewData: ViewData
}
type ViewData {
viewDataField: String
}
9 changes: 9 additions & 0 deletions packages/examples/src/relay/pure-relay/Feedback.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,21 @@ const meta = {
feedback(id: $id) {
...Feedback_feedbackRelayFragment
}
viewData {
...Feedback_viewDataRelayFragment
}
}
`,
variables: { id: "42" },
referenceEntries: {
feedback: (data) => data?.feedback,
viewData: (data) => data?.viewData,
},
resolvers: {
ViewData: () => ({
viewDataField: "View data field",
}),
}
},
} satisfies WithNovaEnvironment<FeedbackStoryRelayQuery, TypeMap>,
} satisfies Meta<typeof FeedbackComponent>;
Expand Down
10 changes: 10 additions & 0 deletions packages/examples/src/relay/pure-relay/Feedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
useOnDeleteFeedback,
useFeedbackTelemetry,
} from "../../events/helpers";
import type { Feedback_viewDataRelayFragment$key } from "./__generated__/Feedback_viewDataRelayFragment.graphql";

type Props = {
feedback: Feedback_feedbackRelayFragment$key;
viewData: Feedback_viewDataRelayFragment$key;
};

export const Feedback_feedbackRelayFragment = graphql`
Expand All @@ -21,9 +23,16 @@ export const Feedback_feedbackRelayFragment = graphql`
}
`;

export const Feedback_viewDataRelayFragment = graphql`
fragment Feedback_viewDataRelayFragment on ViewData {
viewDataField
}
`;

export const FeedbackComponent = (props: Props) => {
const [errorMessage, setErrorMessage] = React.useState<string | null>(null);
const feedback = useFragment(Feedback_feedbackRelayFragment, props.feedback);
const viewData = useFragment(Feedback_viewDataRelayFragment, props.viewData);
const [like, isPending] = useMutation<FeedbackComponent_RelayLikeMutation>(
graphql`
mutation FeedbackComponent_RelayLikeMutation($input: FeedbackLikeInput!) {
Expand Down Expand Up @@ -63,6 +72,7 @@ export const FeedbackComponent = (props: Props) => {
<div style={{ color: "red" }}>{errorMessage}</div>
)}
Feedback: {feedback.message.text}
<div>{viewData.viewDataField}</div>
<button
id="likeButton"
disabled={isPending}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ad913b3

Please sign in to comment.