Skip to content

Commit

Permalink
Merge pull request #1 from danieljharvey/full-schema
Browse files Browse the repository at this point in the history
Full graphql schema (broken)
  • Loading branch information
danieljharvey committed Apr 4, 2020
2 parents 17d6ee0 + 58fbc9f commit e822567
Show file tree
Hide file tree
Showing 14 changed files with 37,608 additions and 319 deletions.
14 changes: 14 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// babel.config.js
module.exports = {
presets: [
[
"@babel/preset-env",
{
targets: {
node: "current"
}
}
],
"@babel/preset-typescript"
]
};
13 changes: 13 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

module.exports = {
// The test environment that will be used for testing
testEnvironment: "jsdom",

// A map from regular expressions to paths to transformers
transform: {
"^.+\\.tsx?$": "ts-jest"
},
testMatch: ["**/*.test.ts"]
};
6 changes: 0 additions & 6 deletions jest.tsc.config.js

This file was deleted.

17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@
"license": "MIT",
"dependencies": {
"fast-check": "^1.23.0",
"prettier": "^2.0.2"
"prettier": "^2.0.2",
"ts-jest": "^25.3.1"
},
"scripts": {
"build": "tsc",
"codegen": "graphql-codegen",
"typescript:watch": "tsc --noEmit --watch",
"test": "./test.sh && jest -c jest.tsc.config.js",
"test:watch": "./test.sh && jest -c jest.tsc.config.js --watch"
"run-codegen": "./test.sh",
"test": "jest",
"test:watch": "jest --watch"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@babel/preset-typescript": "^7.9.0",
"@graphql-codegen/cli": "^1.13.1",
"@types/graphql": "^14.5.0",
"@types/jest": "^25.1.4",
"@types/node": "^13.9.8",
"@types/prettier": "^1.19.1",
"babel-jest": "^25.2.6",
"graphql": "^14.6.0",
"jest": "^25.2.4",
"jest-runner-tsc": "^1.6.0",
"typescript": "^3.8.3",
"@graphql-codegen/cli": "^1.13.1"
"typescript": "^3.8.3"
},
"peerDependencies": {
"@graphql-codegen/cli": "^1.13.1",
Expand Down
115 changes: 115 additions & 0 deletions src/convert.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// import { arbitraryQuery } from "../output/output";
import * as Codegen from "./convert";

describe("includesOneOf", () => {
it("Makes any sense whatsoever", () => {
expect(Codegen.includesOneOf("dog", ["dog"])).toBeTruthy();
});
it("Works with multiple", () => {
expect(Codegen.includesOneOf("dog", ["log", "dog"])).toBeTruthy();
});
it("Works with multiple even with nonsense everywhere", () => {
expect(Codegen.includesOneOf("_____dog___", ["log", "dog"])).toBeTruthy();
});
it("Doesn't find something that's not there", () => {
expect(Codegen.includesOneOf("dog", ["log"])).toBeFalsy();
});
});

describe("sortASTs", () => {
it("Puts mentions later", () => {
const stable: Codegen.NamedType = [
"Object",
"Stable" as Codegen.TypeName,
"fc.record({horse: arbitraryHorse })"
];
const horse: Codegen.NamedType = [
"Object",
"Horse" as Codegen.TypeName,
"fc.record({saddle: arbitrarySaddle})"
];
const saddle: Codegen.NamedType = [
"Object",
"Saddle" as Codegen.TypeName,
"fc.record({chair: arbitraryChair})"
];
const things: Codegen.NamedType = [
"Union",
"Things" as Codegen.TypeName,
"fc.oneof(arbitraryStable, arbitrarySaddle)"
];
const expectedOrder = [saddle, horse, stable, things];
expect(Codegen.sortASTs([things, stable, horse, saddle])).toStrictEqual(
expectedOrder
);
expect(Codegen.sortASTs([stable, horse, saddle, things])).toStrictEqual(
expectedOrder
);
});

it("Does the twitter ones", () => {
const Query: Codegen.NamedType = [
"Object",
"Query" as Codegen.TypeName,
`fc.record({Tweet: arbitraryTweet,Tweets: fc.array(arbitraryTweet),TweetsMeta: arbitraryMeta,User: arbitraryUser,Notifications: fc.array(arbitraryNotification),NotificationsMeta: arbitraryMeta})`
];
const Tweet: Codegen.NamedType = [
"Object",
"Tweet" as Codegen.TypeName,
`fc.record({id: arbitraryID,body: arbitraryString,date: arbitraryDate,Author: arbitraryUser,Stats: arbitraryStat})`
];
const User: Codegen.NamedType = [
"Object",
"User" as Codegen.TypeName,
`fc.record({id: arbitraryID,username: arbitraryString,first_name: arbitraryString,last_name: arbitraryString,full_name: arbitraryString,name: arbitraryString,avatar_url: arbitraryUrl})`
];
const Stat: Codegen.NamedType = [
"Object",
"Stat" as Codegen.TypeName,
`fc.record({views: arbitraryInt,likes: arbitraryInt,retweets: arbitraryInt,responses: arbitraryInt})`
];
const Meta: Codegen.NamedType = [
"Object",
"Meta" as Codegen.TypeName,
`fc.record({count: arbitraryInt})`
];
const Notification: Codegen.NamedType = [
"Object",
"Notification" as Codegen.TypeName,
`fc.record({id: arbitraryID,date: arbitraryDate,type: arbitraryString})`
];
const Mutation: Codegen.NamedType = [
"Object",
"Mutation" as Codegen.TypeName,
`fc.record({createTweet: arbitraryTweet,deleteTweet: arbitraryTweet,markTweetRead: arbitraryBoolean})`
];
const StatOrNotification: Codegen.NamedType = [
"Union",
"StatOrNotification" as Codegen.TypeName,
`fc.oneof(arbitraryStat, arbitraryNotification)`
];

const expectedTweetOrder = [
User,
Stat,
Tweet,
Meta,
Notification,
Query,
Mutation,
StatOrNotification
];
expect(
Codegen.sortASTs([
Query,
Tweet,
User,
Stat,
Meta,
Notification,
Mutation,
StatOrNotification
])
).toStrictEqual(expectedTweetOrder);
});
});

0 comments on commit e822567

Please sign in to comment.