Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Add tests to compile generated code #275

Merged
merged 37 commits into from
Dec 22, 2018
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5505044
Add test to compile typescript-yoga template
Weakky Nov 9, 2018
e76fb8e
Add tests to compile output of graphqlgen with flow
Weakky Nov 10, 2018
693fd78
Use execFile instead of execFileSync
Weakky Nov 10, 2018
f81d73d
fix typescript versions conflict warning
jasonkuhrt Dec 13, 2018
28c83f3
debug: take away flow tests
jasonkuhrt Dec 14, 2018
2e12064
debug: bring back base flow test
jasonkuhrt Dec 14, 2018
6fabb08
Revert "debug: take away flow tests"
jasonkuhrt Dec 14, 2018
eedf697
debug: focus on tests that fail to start/finish on ci
jasonkuhrt Dec 14, 2018
d8e5e97
debug: jest run in band
jasonkuhrt Dec 14, 2018
0bb0732
debug: maybe there is disk contention
jasonkuhrt Dec 14, 2018
353b212
debug: find minimal fix - do not compile
jasonkuhrt Dec 14, 2018
72d1c20
debug: find minimal fix - do not compile flow
jasonkuhrt Dec 14, 2018
a17200f
debug: find minimal fix - do not compile ts
jasonkuhrt Dec 14, 2018
1a38f5e
debug: will removing one flow test suite make it work?
jasonkuhrt Dec 14, 2018
1ac04be
fix: remove disk contention
jasonkuhrt Dec 14, 2018
b35ba9f
fix: sub-class error correctly
jasonkuhrt Dec 14, 2018
bc46511
debug: is issue specific to flow basic?
jasonkuhrt Dec 14, 2018
6e82d04
debug: only one basic test
jasonkuhrt Dec 14, 2018
310904b
debug: logs
jasonkuhrt Dec 14, 2018
4c9e85d
debug: logs
jasonkuhrt Dec 14, 2018
1602058
debug: force build again
jasonkuhrt Dec 14, 2018
27a455a
put test back into todo
jasonkuhrt Dec 14, 2018
730c7b6
debug: jest verbose
jasonkuhrt Dec 14, 2018
bb5ef9c
debug: max-workers flag 2
jasonkuhrt Dec 14, 2018
68d3187
cleanup: remove debug logs
jasonkuhrt Dec 15, 2018
688a86c
chore: refacotr package test scripts
jasonkuhrt Dec 15, 2018
30e7dc5
fix: restore previously failing flow test
jasonkuhrt Dec 15, 2018
0699d08
improvement: nicer flow compile error output
jasonkuhrt Dec 15, 2018
57837be
try: more workers for cci
jasonkuhrt Dec 15, 2018
157fd80
doc
jasonkuhrt Dec 15, 2018
04a1b46
hoist out function
jasonkuhrt Dec 15, 2018
84759be
feedback: use const over let
jasonkuhrt Dec 18, 2018
f7d686f
fix: no-license warning
jasonkuhrt Dec 18, 2018
364f869
chore: make test script what developer uses not ci
jasonkuhrt Dec 18, 2018
6b8bfbf
Merge branch 'master' into tests/compile-templates
Dec 18, 2018
07d48f2
fix: duplicate package key
jasonkuhrt Dec 18, 2018
902e585
Merge branch 'master' into tests/compile-templates
Dec 22, 2018
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
6 changes: 4 additions & 2 deletions packages/graphqlgen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
"build": "npm run lint && tsc --declaration",
"watch": "tsc -w",
"lint": "tslint --project tsconfig.json {src,test}/**/*.ts",
"t": "jest",
"test": "npm run lint && npm run t",
"test:local": "jest",
"test:watch": "jest --watch",
"test": "npm run lint && jest --maxWorkers 4",
"gen": "ts-node --files src/index.ts"
},
"repository": {
Expand Down Expand Up @@ -59,6 +60,7 @@
"@types/prettier": "1.13.2",
"@types/rimraf": "2.0.2",
"@types/yargs": "12.0.1",
"flow-bin": "^0.86.0",
"jest": "23.6.0",
"ts-jest": "23.10.4",
"ts-node": "7.0.1",
Expand Down
22 changes: 20 additions & 2 deletions packages/graphqlgen/src/generators/flow-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import * as os from 'os'
import * as prettier from 'prettier'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module contains bug-fix code in response to the new compilation step we do.


import { GenerateArgs, ModelMap, ContextDefinition } from '../types'
import { GraphQLTypeField, GraphQLTypeObject } from '../source-helper'
import {
GraphQLTypeField,
GraphQLTypeObject,
GraphQLTypeArgument,
} from '../source-helper'
import { upperFirst } from '../utils'
import {
getContextName,
Expand Down Expand Up @@ -197,7 +201,7 @@ function renderInputArgInterface(
${field.arguments
.map(
arg =>
`${arg.name}: ${printFieldLikeType(
`${arg.name}: ${getArgTypePrefix(type, arg)}${printFieldLikeType(
arg as GraphQLTypeField,
modelMap,
)}`,
Expand All @@ -207,6 +211,20 @@ function renderInputArgInterface(
`
}

const getArgTypePrefix = (
type: GraphQLTypeObject,
fieldArg: GraphQLTypeArgument,
): string => {
if (
fieldArg.type.isScalar ||
// Object type includes GQL ID
fieldArg.type.isObject ||
fieldArg.type.isEnum
)
return ''
return upperFirst(type.name) + '_'
}

function renderResolverFunctionInterfaces(
type: GraphQLTypeObject,
modelMap: ModelMap,
Expand Down
6 changes: 2 additions & 4 deletions packages/graphqlgen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function generateCode(
return { generatedTypes, generatedResolvers }
}

function writeTypes(types: string, config: GraphQLGenDefinition): void {
export function writeTypes(types: string, config: GraphQLGenDefinition): void {
// Create generation target folder, if it does not exist
// TODO: Error handling around this
mkdirp.sync(path.dirname(config.output))
Expand All @@ -135,7 +135,7 @@ function writeTypes(types: string, config: GraphQLGenDefinition): void {
)
}

function writeResolversScaffolding(
export function writeResolversScaffolding(
resolvers: CodeFileLike[],
config: GraphQLGenDefinition,
) {
Expand Down Expand Up @@ -172,8 +172,6 @@ function writeResolversScaffolding(
})

console.log(chalk.green(`Resolvers scaffolded at ${outputResolversDir}`))

process.exit(0)
}

function bootstrapYamlFile() {
Expand Down
4 changes: 2 additions & 2 deletions packages/graphqlgen/src/source-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type GraphQLType = GraphQLTypeDefinition & {
isRequired: boolean
}

type GraphQLTypeArgument = {
export type GraphQLTypeArgument = {
name: string
type: GraphQLType
}
Expand Down Expand Up @@ -331,7 +331,7 @@ const graphqlToTypescriptFlow: { [key: string]: string } = {
ID: 'string',
Int: 'number',
Float: 'number',
DateTime: 'string'
DateTime: 'string',
}

export function graphQLToTypecriptFlowType(type: GraphQLType): string {
Expand Down
6 changes: 3 additions & 3 deletions packages/graphqlgen/src/tests/fixtures/context/flow-types.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// @flow

interface Data {
export interface Data {
users: User[];
}

interface Context {
export interface Context {
data: Data;
}

interface User {
export interface User {
id: string;
}
6 changes: 3 additions & 3 deletions packages/graphqlgen/src/tests/fixtures/context/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
interface Data {
export interface Data {
users: User[]
}

interface Context {
export interface Context {
data: Data
}

interface User {
export interface User {
id: string
}
38 changes: 19 additions & 19 deletions packages/graphqlgen/src/tests/fixtures/prisma/flow-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface Review {
checkIn: number;
cleanliness: number;
communication: number;
createdAt: undefined;
createdAt: string;
id: string;
location: number;
stars: number;
Expand Down Expand Up @@ -119,7 +119,7 @@ export interface Amenities {

export interface User {
bookings: any[];
createdAt: undefined;
createdAt: string;
email: string;
firstName: string;
hostingExperiences: any[];
Expand All @@ -136,30 +136,30 @@ export interface User {
responseRate: number | null;
responseTime: number | null;
sentMessages: any[];
updatedAt: undefined;
updatedAt: string;
}

export interface Booking {
id: string;
createdAt: undefined;
createdAt: string;
bookee: any;
place: any;
startDate: undefined;
endDate: undefined;
startDate: any;
endDate: any;
payment: any;
}

export interface Payment {
booking: any;
createdAt: undefined;
createdAt: string;
id: string;
paymentMethod: any;
serviceFee: number;
}

export interface PaymentAccount {
id: string;
createdAt: undefined;
createdAt: string;
type: any | null;
user: any;
payments: any[];
Expand All @@ -170,7 +170,7 @@ export interface PaymentAccount {
export interface PAYMENT_PROVIDER {}

export interface PaypalInformation {
createdAt: undefined;
createdAt: string;
email: string;
id: string;
paymentAccount: any;
Expand All @@ -179,7 +179,7 @@ export interface PaypalInformation {
export interface CreditCardInformation {
cardNumber: string;
country: string;
createdAt: undefined;
createdAt: string;
expiresOnMonth: number;
expiresOnYear: number;
firstName: string;
Expand All @@ -191,21 +191,21 @@ export interface CreditCardInformation {
}

export interface Notification {
createdAt: undefined;
createdAt: string;
id: string;
link: string;
readDate: undefined;
readDate: any;
type: any | null;
user: any;
}

export interface NOTIFICATION_TYPE {}

export interface Message {
createdAt: undefined;
deliveredAt: undefined;
createdAt: string;
deliveredAt: any;
id: string;
readAt: undefined;
readAt: any;
}

export interface Pricing {
Expand Down Expand Up @@ -242,21 +242,21 @@ export interface Policies {
checkInEndTime: number;
checkInStartTime: number;
checkoutTime: number;
createdAt: undefined;
createdAt: string;
id: string;
updatedAt: undefined;
updatedAt: string;
}

export interface HouseRules {
additionalRules: string | null;
createdAt: undefined;
createdAt: string;
id: string;
partiesAndEventsAllowed: boolean | null;
petsAllowed: boolean | null;
smokingAllowed: boolean | null;
suitableForChildren: boolean | null;
suitableForInfants: boolean | null;
updatedAt: undefined;
updatedAt: string;
}

export interface Reservation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`basic enum 1`] = `
// Code generated by github.com/prisma/graphqlgen, DO NOT EDIT.

import type { GraphQLResolveInfo } from \\"graphql\\";
import type { User } from \\"../../../fixtures/enum/types-flow\\";
import type { User } from \\"../../fixtures/enum/types-flow\\";
type Context = any;

type EnumAnnotation = \\"EDITOR\\" | \\"COLLABORATOR\\";
Expand Down Expand Up @@ -164,7 +164,7 @@ exports[`basic scalar 1`] = `
// Code generated by github.com/prisma/graphqlgen, DO NOT EDIT.

import type { GraphQLResolveInfo } from \\"graphql\\";
import type { AddMemberPayload } from \\"../../../fixtures/scalar/flow-types\\";
import type { AddMemberPayload } from \\"../../fixtures/scalar/flow-types\\";
type Context = any;

// Types for Mutation
Expand All @@ -176,7 +176,7 @@ export interface Mutation_AddMemberData {
}

export interface Mutation_Args_AddMember {
data: AddMemberData;
data: Mutation_AddMemberData;
}

export type Mutation_AddMember_Resolver = (
Expand Down Expand Up @@ -276,7 +276,7 @@ exports[`basic schema 1`] = `
// Code generated by github.com/prisma/graphqlgen, DO NOT EDIT.

import type { GraphQLResolveInfo } from \\"graphql\\";
import type { Number } from \\"../../../fixtures/basic/types-flow\\";
import type { Number } from \\"../../fixtures/basic/types-flow\\";
type Context = any;

// Types for Query
Expand Down Expand Up @@ -614,11 +614,7 @@ exports[`basic union 1`] = `
// Code generated by github.com/prisma/graphqlgen, DO NOT EDIT.

import type { GraphQLResolveInfo } from \\"graphql\\";
import type {
User,
Student,
Professor
} from \\"../../../fixtures/union/flow-types\\";
import type { User, Student, Professor } from \\"../../fixtures/union/flow-types\\";
type Context = any;

// Types for User
Expand Down Expand Up @@ -791,8 +787,8 @@ exports[`context 1`] = `
// Code generated by github.com/prisma/graphqlgen, DO NOT EDIT.

import type { GraphQLResolveInfo } from \\"graphql\\";
import type { User } from \\"../../../fixtures/context/flow-types\\";
import type { Context } from \\"../../../fixtures/context/flow-types\\";
import type { User } from \\"../../fixtures/context/flow-types\\";
import type { Context } from \\"../../fixtures/context/flow-types\\";

// Types for Query
export const Query_defaultResolvers = {};
Expand Down Expand Up @@ -894,7 +890,7 @@ exports[`defaultName 1`] = `
// Code generated by github.com/prisma/graphqlgen, DO NOT EDIT.

import type { GraphQLResolveInfo } from \\"graphql\\";
import type { NumberNode } from \\"../../../fixtures/defaultName/flow-types\\";
import type { NumberNode } from \\"../../fixtures/defaultName/flow-types\\";
type Context = any;

// Types for Query
Expand Down Expand Up @@ -1232,7 +1228,7 @@ exports[`subscription 1`] = `
// Code generated by github.com/prisma/graphqlgen, DO NOT EDIT.

import type { GraphQLResolveInfo } from \\"graphql\\";
import type { User } from \\"../../../fixtures/subscription/flow-types\\";
import type { User } from \\"../../fixtures/subscription/flow-types\\";
type Context = any;

// Types for Subscription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import type {
Message,
AuthPayload,
MutationResult
} from \\"../../../fixtures/prisma/flow-types\\";
} from \\"../../fixtures/prisma/flow-types\\";
type Context = any;

type PLACE_SIZES =
Expand Down
Loading