;
44 |
--------------------------------------------------------------------------------
/packages/tag/src/no-transform.js:
--------------------------------------------------------------------------------
1 | export { default as gql } from "graphql-tag";
2 |
3 | export const getDocumentNode = (node) => node;
4 |
--------------------------------------------------------------------------------
/pnpm-workspace.yaml:
--------------------------------------------------------------------------------
1 | packages:
2 | - "packages/*"
3 | - "test-app"
4 |
--------------------------------------------------------------------------------
/test-app/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | plugins: ["@ts-gql"],
3 | rules: {
4 | "@ts-gql/ts-gql": "error",
5 | },
6 | };
7 |
--------------------------------------------------------------------------------
/test-app/next-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 |
5 | // NOTE: This file should not be edited
6 | // see https://nextjs.org/docs/basic-features/typescript for more information.
7 |
--------------------------------------------------------------------------------
/test-app/next.config.js:
--------------------------------------------------------------------------------
1 | module.exports = require("@ts-gql/next").withTsGql();
2 |
--------------------------------------------------------------------------------
/test-app/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@ts-gql/test-app",
3 | "version": "0.1.30",
4 | "private": true,
5 | "license": "MIT",
6 | "scripts": {
7 | "build": "ts-gql build"
8 | },
9 | "dependencies": {
10 | "@apollo/client": "^3.6.9",
11 | "@ts-gql/babel-plugin": "^0.1.0",
12 | "@ts-gql/compiler": "^0.16.0",
13 | "@ts-gql/eslint-plugin": "^0.9.0",
14 | "@ts-gql/fetch": "^0.1.2",
15 | "@ts-gql/next": "^17.0.0",
16 | "@ts-gql/tag": "^0.7.0",
17 | "@types/node": "^22.13.1",
18 | "@types/react": "^16.9.43",
19 | "@types/react-dom": "^16.9.8",
20 | "@typescript-eslint/parser": "^6.3.0",
21 | "next": "^12.0.3",
22 | "raw-loader": "^4.0.1",
23 | "react": "^16.14.0",
24 | "react-dom": "^16.14.0",
25 | "urql": "^2.2.0"
26 | },
27 | "ts-gql": {
28 | "schema": "schema.graphql",
29 | "mode": "mixed"
30 | },
31 | "repository": "https://github.com/Thinkmill/ts-gql/tree/main/test-app"
32 | }
33 |
--------------------------------------------------------------------------------
/test-app/pages/_app.tsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { AppProps } from "next/app";
3 |
4 | export default ({ Component, pageProps }: AppProps) => {
5 | return ;
6 | };
7 |
--------------------------------------------------------------------------------
/test-app/pages/apollo.tsx:
--------------------------------------------------------------------------------
1 | import { gql } from "@ts-gql/tag/no-transform";
2 | import { createFetcher } from "@ts-gql/fetch";
3 | import * as urql from "urql";
4 | import * as apollo from "@apollo/client";
5 |
6 | const query2 = gql`
7 | query MyQueryApollo($thing: String) {
8 | optional(thing: $thing)
9 | }
10 | ` as import("../__generated__/ts-gql/MyQueryApollo").type;
11 |
12 | const someFragment = gql`
13 | fragment Something2Apollo_x on Query {
14 | hello
15 | someObj {
16 | id
17 | other
18 | }
19 | arr {
20 | id
21 | other
22 | }
23 | thing {
24 | id
25 | ... on ImplementationOfThing {
26 | something
27 | }
28 | }
29 | }
30 | ` as import("../__generated__/ts-gql/Something2Apollo_x").type;
31 |
32 | const otherFragment = gql`
33 | fragment OtherFragment_x on Query {
34 | hello
35 | someObj {
36 | id
37 | other
38 | }
39 | arr {
40 | id
41 | other
42 | }
43 | thing {
44 | id
45 | ... on ImplementationOfThing {
46 | something
47 | }
48 | }
49 | }
50 | ` as import("../__generated__/ts-gql/OtherFragment_x").type;
51 |
52 | console.log(otherFragment);
53 |
54 | const query = gql`
55 | query SomeQueryApollo($arg: String!) {
56 | optional(thing: $arg)
57 | ye: something
58 |
59 | ...Something2Apollo_x
60 | }
61 | ${someFragment}
62 | ` as import("../__generated__/ts-gql/SomeQueryApollo").type;
63 |
64 | let someMutation = gql`
65 | mutation SomeMutationApollo($arg: String!) {
66 | optional(thing: $arg)
67 | ye: something
68 | }
69 | ` as import("../__generated__/ts-gql/SomeMutationApollo").type;
70 |
71 | console.log({ query, someMutation });
72 |
73 | const fetchGraphQL = createFetcher("");
74 |
75 | fetchGraphQL(someMutation, { arg: "" });
76 | fetchGraphQL(query2);
77 |
78 | export default () => {
79 | // let client = useApolloClient();
80 | // const { data } = useQuery(query, { variables: { arg: "" } });
81 | // ;
82 | // data.hello;
83 | // data.another;
84 | const [stuff, mutate] = urql.useMutation(someMutation);
85 | mutate();
86 | mutate({
87 | arg: "",
88 | }).then((x) => {
89 | x.data?.__typename;
90 | });
91 |
92 | stuff.data?.__typename;
93 |
94 | const [apolloMutate, apolloStuff] = apollo.useMutation(someMutation, {
95 | variables: {
96 | arg: "",
97 | },
98 | });
99 | apolloStuff.data?.optional;
100 |
101 | apolloMutate({
102 | variables: {
103 | arg: "",
104 | },
105 | });
106 |
107 | // data.hello;
108 | // data.other;
109 | // data.aTh;
110 | // data.aThin;
111 |
112 | return "something";
113 | };
114 |
--------------------------------------------------------------------------------
/test-app/pages/thing/thing.tsx:
--------------------------------------------------------------------------------
1 | import { gql } from "@ts-gql/tag/no-transform";
2 | import { ApolloClient, InMemoryCache, useQuery } from "@apollo/client";
3 | import { useMemo } from "react";
4 |
5 | const postListFragment = gql`
6 | fragment PostList_posts on Post {
7 | title
8 | author {
9 | name
10 | }
11 | }
12 | ` as import("../../__generated__/ts-gql/PostList_posts").type;
13 |
14 | const authorListFragment = gql`
15 | fragment AuthorList_author on Author {
16 | name
17 | }
18 | ` as import("../../__generated__/ts-gql/AuthorList_author").type;
19 |
20 | console.log(authorListFragment);
21 |
22 | const query = gql`
23 | query PostListPage {
24 | posts {
25 | title
26 | ...PostList_posts
27 | }
28 | }
29 | ${postListFragment}
30 | ` as import("../../__generated__/ts-gql/PostListPage").type;
31 |
32 | export default function Test() {
33 | const client = useMemo(() => {
34 | return new ApolloClient({
35 | uri: "http://localhost:3000/api/graphql",
36 | cache: new InMemoryCache(),
37 | });
38 | }, []);
39 | const { loading, data, error } = useQuery(query, { client });
40 | return {JSON.stringify({ loading, data, error }, null, 2)}
;
41 | }
42 |
--------------------------------------------------------------------------------
/test-app/schema.graphql:
--------------------------------------------------------------------------------
1 | type Query {
2 | hello: String!
3 | other: Boolean!
4 | another: String!
5 | something: String
6 | someObj: OutputThing!
7 | arr: [OutputThing!]!
8 | thing: Thing!
9 | optional(thing: String): String!
10 | oneMore(thing: String, other: Something!): String! @deprecated(reason: "Blah")
11 | posts: [Post!]!
12 | }
13 |
14 | type Mutation {
15 | hello: String!
16 | other: Boolean!
17 | another: String!
18 | something: String
19 | optional(thing: String): String!
20 | oneMore(thing: String, other: Something!): String!
21 | }
22 |
23 | interface Thing {
24 | id: ID!
25 | }
26 |
27 | type ImplementationOfThing implements Thing {
28 | id: ID!
29 | something: String!
30 | }
31 |
32 | type OutputThing {
33 | id: ID!
34 | other: String!
35 | }
36 |
37 | input Something {
38 | yes: Boolean
39 | no: String!
40 | }
41 |
42 | type Post {
43 | title: String!
44 | author: Author!
45 | }
46 |
47 | type Author {
48 | name: String!
49 | }
50 |
--------------------------------------------------------------------------------
/test-app/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "lib": ["dom", "dom.iterable", "esnext"],
5 | "allowJs": true,
6 | "skipLibCheck": true,
7 | "strict": true,
8 | "forceConsistentCasingInFileNames": true,
9 | "noEmit": true,
10 | "esModuleInterop": true,
11 | "module": "esnext",
12 | "moduleResolution": "node",
13 | "resolveJsonModule": true,
14 | "isolatedModules": true,
15 | "jsx": "preserve"
16 | },
17 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
18 | "exclude": ["node_modules"]
19 | }
20 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "esnext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
4 | "module": "esnext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
5 | "jsx": "preserve" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
6 | "declaration": true /* Generates corresponding '.d.ts' file. */,
7 | "noEmit": true /* Do not emit outputs. */,
8 | "isolatedModules": true /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */,
9 | "strict": true /* Enable all strict type-checking options. */,
10 | "moduleResolution": "bundler" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
11 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
12 | "resolveJsonModule": true,
13 | "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
14 | "skipLibCheck": true,
15 | "useUnknownInCatchVariables": false
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/types/fixturez.d.ts:
--------------------------------------------------------------------------------
1 | type Opts = {
2 | glob?: string | Array;
3 | root?: string;
4 | cleanup?: boolean;
5 | };
6 |
7 | declare module "fixturez" {
8 | export default function (
9 | cwd: string,
10 | opts?: Opts
11 | ): {
12 | find: (fixture: string) => string;
13 | temp: () => string;
14 | copy: (fixture: string) => string;
15 | cleanup: () => void;
16 | };
17 | }
18 |
--------------------------------------------------------------------------------