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

Commit

Permalink
test: actually compile the code generated by tests (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
Weakky authored and Jason Kuhrt committed Dec 22, 2018
1 parent 12548ed commit 97fa5a6
Show file tree
Hide file tree
Showing 19 changed files with 306 additions and 119 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ jobs:
steps:
- checkout
- run: yarn install
- run: yarn test
- run: yarn test:ci
# - run: npx semantic-release
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"scripts": {
"build": "cd packages/graphqlgen-json-schema && yarn build && cd ../graphqlgen && yarn build",
"test": "yarn build && cd packages/graphqlgen && yarn test",
"test:ci": "yarn build && cd packages/graphqlgen && yarn test:ci",
"fix:prettier": "yarn prettier --write './**/*.{md,ts,js,graphql,yaml}'"
},
"workspaces": [
Expand Down
8 changes: 5 additions & 3 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": "jest",
"test:watch": "jest --watch",
"test:ci": "npm run lint && jest --maxWorkers 4",
"gen": "ts-node --files src/index.ts"
},
"repository": {
Expand Down Expand Up @@ -58,7 +59,8 @@
"@types/node": "10.12.18",
"@types/prettier": "1.15.2",
"@types/rimraf": "2.0.2",
"@types/yargs": "12.0.2",
"@types/yargs": "12.0.1",
"flow-bin": "^0.86.0",
"jest": "23.6.0",
"ts-jest": "23.10.5",
"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'

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
2 changes: 1 addition & 1 deletion 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
defaultValue?: unknown
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

0 comments on commit 97fa5a6

Please sign in to comment.