Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add passthrough schema config support with GQL Codegen #650

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions __tests__/__snapshots__/babel.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function nest1() {

↓ ↓ ↓ ↓ ↓ ↓

import * as Ved68302f0b7c4c812ed026e4ca84e5c30072a6ca from './node_modules/.cache/graphql-let/input-Viewer-Partial.ts';
const { useViewerQuery } = Ved68302f0b7c4c812ed026e4ca84e5c30072a6ca;
import * as Vc32847a88b2fa71e5454830d34259a5bc60114db from './node_modules/.cache/graphql-let/input-Viewer-Partial.ts';
const { useViewerQuery } = Vc32847a88b2fa71e5454830d34259a5bc60114db;

function nest1() {
function nest2() {
Expand All @@ -61,7 +61,7 @@ function nest1() {
`;

exports[`graphql-let macro-gql: node_modules/.cache/graphql-let/__types__.tsx 1`] = `
/* 497fd3cc5b4adebcf3aada3a62576980d87716cf
/* 8ccc57a676cae37de529cf6255eca4f83f2dd47f
* This file is automatically generated by graphql-let. */

import { GraphQLResolveInfo } from 'graphql';
Expand Down Expand Up @@ -211,7 +211,7 @@ export type IResolvers<ContextType = any> = Resolvers<ContextType>;
`;

exports[`graphql-let macro-gql: node_modules/.cache/graphql-let/input-Viewer-Partial.ts 1`] = `
/* ed68302f0b7c4c812ed026e4ca84e5c30072a6ca
/* c32847a88b2fa71e5454830d34259a5bc60114db
* This file is automatically generated by graphql-let. */

import * as Types from './__types__';
Expand Down Expand Up @@ -279,7 +279,7 @@ export type ViewerQueryResult = Apollo.QueryResult<ViewerQuery, ViewerQueryVaria
`;

exports[`graphql-let macro-gql: node_modules/@types/graphql-let/__generated__/__types__.d.ts 1`] = `
/* 497fd3cc5b4adebcf3aada3a62576980d87716cf
/* 8ccc57a676cae37de529cf6255eca4f83f2dd47f
* This file is automatically generated by graphql-let. */

import { GraphQLResolveInfo } from 'graphql';
Expand Down Expand Up @@ -378,7 +378,7 @@ export declare type IResolvers<ContextType = any> = Resolvers<ContextType>;
`;

exports[`graphql-let macro-gql: node_modules/@types/graphql-let/__generated__/input-Viewer-Partial.d.ts 1`] = `
/* ed68302f0b7c4c812ed026e4ca84e5c30072a6ca
/* c32847a88b2fa71e5454830d34259a5bc60114db
* This file is automatically generated by graphql-let. */

import * as Types from "./__types__";
Expand Down Expand Up @@ -432,15 +432,15 @@ export declare type __GraphQLLetTypeInjection = {
`;

exports[`graphql-let macro-gql: node_modules/@types/graphql-let/index.d.ts 1`] = `
import Ted68302f0b7c4c812ed026e4ca84e5c30072a6ca from './__generated__/input-Viewer-Partial';
import Tc32847a88b2fa71e5454830d34259a5bc60114db from './__generated__/input-Viewer-Partial';
export function gql(gql: \`
# import Partial from './documents/partial.graphql'
query Viewer {
viewer {
...Partial
}
}
\`): Ted68302f0b7c4c812ed026e4ca84e5c30072a6ca.__GraphQLLetTypeInjection;
\`): Tc32847a88b2fa71e5454830d34259a5bc60114db.__GraphQLLetTypeInjection;

`;

Expand Down Expand Up @@ -482,8 +482,8 @@ function nest1() {

↓ ↓ ↓ ↓ ↓ ↓

import * as V479e1b051ff6ed35fa952ede1d8cda20a5b8d114 from './node_modules/.cache/graphql-let/input-Viewer-Partial.ts';
const { useViewerQuery } = V479e1b051ff6ed35fa952ede1d8cda20a5b8d114;
import * as V543c0feb9af268a54dd482a31d349212e219a42e from './node_modules/.cache/graphql-let/input-Viewer-Partial.ts';
const { useViewerQuery } = V543c0feb9af268a54dd482a31d349212e219a42e;

function nest1() {
function nest2() {
Expand All @@ -503,7 +503,7 @@ function nest1() {
`;

exports[`graphql-let macro-load: node_modules/.cache/graphql-let/__types__.tsx 1`] = `
/* 497fd3cc5b4adebcf3aada3a62576980d87716cf
/* 8ccc57a676cae37de529cf6255eca4f83f2dd47f
* This file is automatically generated by graphql-let. */

import { GraphQLResolveInfo } from 'graphql';
Expand Down Expand Up @@ -653,7 +653,7 @@ export type IResolvers<ContextType = any> = Resolvers<ContextType>;
`;

exports[`graphql-let macro-load: node_modules/.cache/graphql-let/input-Viewer-Partial.ts 1`] = `
/* 479e1b051ff6ed35fa952ede1d8cda20a5b8d114
/* 543c0feb9af268a54dd482a31d349212e219a42e
* This file is automatically generated by graphql-let. */

import * as Types from './__types__';
Expand Down Expand Up @@ -721,7 +721,7 @@ export type ViewerQueryResult = Apollo.QueryResult<ViewerQuery, ViewerQueryVaria
`;

exports[`graphql-let macro-load: node_modules/@types/graphql-let/__generated__/__types__.d.ts 1`] = `
/* 497fd3cc5b4adebcf3aada3a62576980d87716cf
/* 8ccc57a676cae37de529cf6255eca4f83f2dd47f
* This file is automatically generated by graphql-let. */

import { GraphQLResolveInfo } from 'graphql';
Expand Down Expand Up @@ -820,7 +820,7 @@ export declare type IResolvers<ContextType = any> = Resolvers<ContextType>;
`;

exports[`graphql-let macro-load: node_modules/@types/graphql-let/__generated__/input-Viewer-Partial.d.ts 1`] = `
/* 479e1b051ff6ed35fa952ede1d8cda20a5b8d114
/* 543c0feb9af268a54dd482a31d349212e219a42e
* This file is automatically generated by graphql-let. */

import * as Types from "./__types__";
Expand Down Expand Up @@ -874,8 +874,8 @@ export declare type __GraphQLLetTypeInjection = {
`;

exports[`graphql-let macro-load: node_modules/@types/graphql-let/index.d.ts 1`] = `
import T479e1b051ff6ed35fa952ede1d8cda20a5b8d114 from './__generated__/input-Viewer-Partial';
export function load(load: \`./documents/viewer.graphql\`): T479e1b051ff6ed35fa952ede1d8cda20a5b8d114.__GraphQLLetTypeInjection;
import T543c0feb9af268a54dd482a31d349212e219a42e from './__generated__/input-Viewer-Partial';
export function load(load: \`./documents/viewer.graphql\`): T543c0feb9af268a54dd482a31d349212e219a42e.__GraphQLLetTypeInjection;

`;

Expand All @@ -896,7 +896,7 @@ Array [
`;

exports[`graphql-let plugin: node_modules/.cache/graphql-let/__types__.tsx 1`] = `
/* 497fd3cc5b4adebcf3aada3a62576980d87716cf
/* 8ccc57a676cae37de529cf6255eca4f83f2dd47f
* This file is automatically generated by graphql-let. */

import { GraphQLResolveInfo } from 'graphql';
Expand Down Expand Up @@ -1046,7 +1046,7 @@ export type IResolvers<ContextType = any> = Resolvers<ContextType>;
`;

exports[`graphql-let plugin: node_modules/.cache/graphql-let/input-Viewer.ts 1`] = `
/* af49db201f15491f76f205723da63c0469e1a52e
/* 29cce2371467ad0780bd7b0f5d9182cba42ce3e1
* This file is automatically generated by graphql-let. */

import * as Types from './__types__';
Expand Down Expand Up @@ -1103,7 +1103,7 @@ export type ViewerQueryResult = Apollo.QueryResult<ViewerQuery, ViewerQueryVaria
`;

exports[`graphql-let plugin: node_modules/@types/graphql-let/__generated__/__types__.d.ts 1`] = `
/* 497fd3cc5b4adebcf3aada3a62576980d87716cf
/* 8ccc57a676cae37de529cf6255eca4f83f2dd47f
* This file is automatically generated by graphql-let. */

import { GraphQLResolveInfo } from 'graphql';
Expand Down Expand Up @@ -1202,7 +1202,7 @@ export declare type IResolvers<ContextType = any> = Resolvers<ContextType>;
`;

exports[`graphql-let plugin: node_modules/@types/graphql-let/__generated__/input-Viewer.d.ts 1`] = `
/* af49db201f15491f76f205723da63c0469e1a52e
/* 29cce2371467ad0780bd7b0f5d9182cba42ce3e1
* This file is automatically generated by graphql-let. */

import * as Types from "./__types__";
Expand Down Expand Up @@ -1251,8 +1251,8 @@ export declare type __GraphQLLetTypeInjection = {
`;

exports[`graphql-let plugin: node_modules/@types/graphql-let/index.d.ts 1`] = `
import Taf49db201f15491f76f205723da63c0469e1a52e from './__generated__/input-Viewer';
export function gql(gql: \`query Viewer { viewer { name } }\`): Taf49db201f15491f76f205723da63c0469e1a52e.__GraphQLLetTypeInjection;
import T29cce2371467ad0780bd7b0f5d9182cba42ce3e1 from './__generated__/input-Viewer';
export function gql(gql: \`query Viewer { viewer { name } }\`): T29cce2371467ad0780bd7b0f5d9182cba42ce3e1.__GraphQLLetTypeInjection;

`;

Expand Down Expand Up @@ -1283,8 +1283,8 @@ function nest1() {

↓ ↓ ↓ ↓ ↓ ↓

import * as Vaf49db201f15491f76f205723da63c0469e1a52e from './node_modules/.cache/graphql-let/input-Viewer.ts';
const { useViewerQuery } = Vaf49db201f15491f76f205723da63c0469e1a52e;
import * as V29cce2371467ad0780bd7b0f5d9182cba42ce3e1 from './node_modules/.cache/graphql-let/input-Viewer.ts';
const { useViewerQuery } = V29cce2371467ad0780bd7b0f5d9182cba42ce3e1;

function nest1() {
function nest2() {
Expand Down
12 changes: 6 additions & 6 deletions __tests__/__snapshots__/hmr.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`HMR should effect to both schema and documents properly 1`] = `
Object {
"document": "/* ed4a8c87ea91744c5a0da500b4e2241a9e274fe4
"document": "/* 81d9f5a2c409d51ec80fb127e2ba3084cdf32df4
* This file is automatically generated by graphql-let. */

import * as Types from \\"graphql-let/__generated__/__types__\\";
Expand Down Expand Up @@ -44,7 +44,7 @@ export declare type ViewerQueryHookResult = ReturnType<typeof useViewerQuery>;
export declare type ViewerLazyQueryHookResult = ReturnType<typeof useViewerLazyQuery>;
export declare type ViewerQueryResult = Apollo.QueryResult<ViewerQuery, ViewerQueryVariables>;",
"documentDtsPath": "src/viewer.graphql.d.ts",
"schema": "/* ef793228f2d1b2eead0e43c1a0fde16030975126
"schema": "/* 8a40de3bd5cb7be935ca4231de35e15c1d42c906
* This file is automatically generated by graphql-let. */

import { GraphQLResolveInfo } from 'graphql';
Expand Down Expand Up @@ -144,7 +144,7 @@ export declare type IResolvers<ContextType = any> = Resolvers<ContextType>;",

exports[`HMR should effect to both schema and documents properly 2`] = `
Object {
"document": "/* 32aaf391d0a955fdd8f7194ff429aa3e85625b6c
"document": "/* 8329e70ab73821fd3cf81bd1961ddfaa6df5a13f
* This file is automatically generated by graphql-let. */

import * as Types from \\"graphql-let/__generated__/__types__\\";
Expand Down Expand Up @@ -186,7 +186,7 @@ export declare type ViewerQueryHookResult = ReturnType<typeof useViewerQuery>;
export declare type ViewerLazyQueryHookResult = ReturnType<typeof useViewerLazyQuery>;
export declare type ViewerQueryResult = Apollo.QueryResult<ViewerQuery, ViewerQueryVariables>;",
"documentDtsPath": "src/viewer.graphql.d.ts",
"schema": "/* ef793228f2d1b2eead0e43c1a0fde16030975126
"schema": "/* 8a40de3bd5cb7be935ca4231de35e15c1d42c906
* This file is automatically generated by graphql-let. */

import { GraphQLResolveInfo } from 'graphql';
Expand Down Expand Up @@ -286,7 +286,7 @@ export declare type IResolvers<ContextType = any> = Resolvers<ContextType>;",

exports[`HMR should effect to both schema and documents properly 3`] = `
Object {
"document": "/* a293e11847f8d46befbb501df4f1624af820a68d
"document": "/* f83c2c1a943dd8fce4f4c1125fd4932be5db2317
* This file is automatically generated by graphql-let. */

import * as Types from \\"graphql-let/__generated__/__types__\\";
Expand Down Expand Up @@ -328,7 +328,7 @@ export declare type ViewerQueryHookResult = ReturnType<typeof useViewerQuery>;
export declare type ViewerLazyQueryHookResult = ReturnType<typeof useViewerLazyQuery>;
export declare type ViewerQueryResult = Apollo.QueryResult<ViewerQuery, ViewerQueryVariables>;",
"documentDtsPath": "src/viewer.graphql.d.ts",
"schema": "/* e5b0eef82543e1120efe07c2db4de3dd4f97abfc
"schema": "/* 8d18fb828b21c0c966d4a480b96ddea493cc61b2
* This file is automatically generated by graphql-let. */

import { GraphQLResolveInfo } from 'graphql';
Expand Down
28 changes: 25 additions & 3 deletions __tests__/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {
createSystem,
createVirtualCompilerHost,
} from '@typescript/vfs';
import { fetch as nodeFetch } from '@whatwg-node/fetch';
import { ok } from 'assert';
import { fetch } from 'cross-fetch';
import { fetch as crossFetch } from 'cross-fetch';
import fs, { Dirent } from 'fs';
import makeDir from 'make-dir';
import { dirname, join } from 'path';
Expand All @@ -15,6 +16,7 @@ import gen from '../src/gen';
import { AbsFn, prepareFixtures } from '../src/lib/__tools/file';

jest.mock('cross-fetch');
jest.mock('@whatwg-node/fetch');

const getLib = (name: string) => {
const lib = dirname(require.resolve('typescript'));
Expand Down Expand Up @@ -115,11 +117,22 @@ describe('"graphql-let" command', () => {
test('handles schema objects', async () => {
// eslint-disable-next-line
const schemaJson = require('./__fixtures/tsconfig/schema.json');
(fetch as any).mockReturnValue({
(crossFetch as any).mockReturnValue({
json() {
return { data: schemaJson };
},
});

// This fetch is used by the schema loader
(nodeFetch as any).mockReturnValue({
headers: new Map([['content-type', 'application/json']]),
status: 200,
statusText: 'OK',
text() {
return JSON.stringify({ data: schemaJson });
},
});

let error = null;
try {
await gen({
Expand All @@ -130,10 +143,19 @@ describe('"graphql-let" command', () => {
console.log(e);
error = e;
}

ok(error === null, error);
// It's called twice in the library. Why?
// expect(fetch).toHaveBeenCalledTimes(1);
expect(fetch).toHaveBeenCalledWith(
expect(nodeFetch).toHaveBeenCalledWith(
'http://localhost:3000/graphql',
expect.objectContaining({
headers: expect.objectContaining({
Authorization: 'GRAPHQL-LET',
}),
}),
);
expect(crossFetch).toHaveBeenCalledWith(
'http://localhost:3000/graphql',
expect.objectContaining({
headers: expect.objectContaining({
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@
"@babel/helper-plugin-utils": "7.14.5",
"@babel/parser": "7.15.5",
"@babel/traverse": "7.15.4",
"@graphql-tools/import": "6.4.0",
"@graphql-tools/apollo-engine-loader": "^7.0.0",
"@graphql-tools/code-file-loader": "^7.0.0",
"@graphql-tools/git-loader": "^7.0.0",
"@graphql-tools/github-loader": "^7.0.0",
"@graphql-tools/graphql-file-loader": "^7.0.0",
"@graphql-tools/import": "^6.7.0",
"@graphql-tools/json-file-loader": "^7.0.0",
"@graphql-tools/load": "^7.0.0",
"@graphql-tools/url-loader": "^7.0.0",
"caller": "1.0.1",
"gensync": "1.0.0-beta.2",
"globby": "11.0.4",
Expand Down Expand Up @@ -65,8 +73,6 @@
"@graphql-codegen/typescript-operations": "1.18.4",
"@graphql-codegen/typescript-react-apollo": "2.3.1",
"@graphql-codegen/typescript-resolvers": "1.19.1",
"@graphql-tools/graphql-file-loader": "6.2.7",
"@graphql-tools/import": "6.4.0",
"@jest/transform": "27.2.0",
"@jest/types": "27.1.0",
"@types/babel-plugin-macros": "2.8.5",
Expand Down
Loading