Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
tgriesser committed Nov 4, 2018
1 parent 86e7e5c commit b4b1ed5
Show file tree
Hide file tree
Showing 22 changed files with 658 additions and 341 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 1.0.0

Initial release
Empty file added CONTRIBUTING.md
Empty file.
40 changes: 29 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
## GQLit
## GQLiteral

Literate, strongly typed GraphQL schema construction for JavaScript.
Simple, strongly typed GraphQL schema construction for TypeScript/JavaScript

Combines the best practices in building out a GraphQL server layer without the boilerplate.
Combines the best practices from building real-world GraphQL servers without the boilerplate or excessive imports. Compose types with [abstract types](#GQLiteralAbstractType) and [type mixing](#Type-combination).

Inspired by real-world use of graphql-js, apollo, graphene, and graphql-ruby.
Inspired by use of [graphql-tools](https://github.com/apollographql/graphql-tools), [graphene](https://docs.graphene-python.org/en/latest/), and [graphql-ruby](https://github.com/rmosolgo/graphql-ruby).

Provides full control of your schema, with added benefits like dynamic schemas based on user permissions. Check out the `/examples` for some sample uses.

### Installation

```
yarn install gqliteral
```

### Features:

**_ Type combination _**
##### Type combination

Ever have a situation where your input types look eerily simliar to your output types, yet you need to define them both by hand in the schema? Or maybe you have an interface shared by several types, and each time you add a field to the interface you need to remember to add it to the types.

**_ No circular reference issues _**
##### No circular reference issues

One of the problems with GraphQL construction is the self-referential types and the

**_ Awesome intellisense _**
##### Awesome intellisense

Leverages type generation internally so you don't have to.

**_ Great error messages _**
##### Great error messages

We want you to know where things went wrong, not spend time trying to figure out cryptic error messages.

Expand All @@ -36,8 +42,20 @@ Ever notice that your input types and output types are usually fairly similar? M

### API:

#### GQLitType
#### GQLiteralObject

#### GQLiteralInputObject

#### GQLiteralInterface

#### GQLiteralObject

#### GQLiteralUnion

#### GQLiteralSchema

#### GQLiteralEnum

#### GQLitInputType
#### GQLiteralAbstractType

####
### License
2 changes: 1 addition & 1 deletion examples/simple-app/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "gqlit-simple-app",
"name": "gqliteral-simple-app",
"dependencies": {
"express": "^4.16.4",
"apollo-server-express": "^2.1.0"
Expand Down
4 changes: 2 additions & 2 deletions examples/simple-app/src/types/blog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GQLitObject } from "../../../../src";
import { GQLiteralObject } from "../../../../src";

export const Blog = GQLitObject("Blog", t => {
export const Blog = GQLiteralObject("Blog", t => {
t.field("id", "ID");
t.field("title", "String", { description: "The title of the blog" });
t.list("posts", "Post");
Expand Down
13 changes: 8 additions & 5 deletions examples/simple-app/src/types/comment.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { GQLitObject, GQLitInputObject } from "../../../../src";
import { GQLiteralObject, GQLiteralInputObject } from "../../../../src";

export const Comment = GQLitObject("Comment", t => {
export const Comment = GQLiteralObject("Comment", t => {
t.field("id", "ID");
});

export const CreateCommentInput = GQLitInputObject("CreateCommentInput", t => {
t.mix("Comment");
});
export const CreateCommentInput = GQLiteralInputObject(
"CreateCommentInput",
t => {
t.mix("Comment");
}
);
4 changes: 2 additions & 2 deletions examples/simple-app/src/types/node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GQLitInterface } from "../../../../src";
import { GQLiteralInterface } from "../../../../src";

export const Node = GQLitInterface("Node", t => {
export const Node = GQLiteralInterface("Node", t => {
t.resolveType(() => {});
});
6 changes: 3 additions & 3 deletions examples/simple-app/src/types/post.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GQLitObject } from '../../../../src';
import { GQLiteralObject } from "../../../../src";

export const Post = GQLitObject('Post', t => {
t.implements('Node');
export const Post = GQLiteralObject("Post", t => {
t.implements("Node");
});
4 changes: 2 additions & 2 deletions examples/simple-app/src/types/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GQLitObject } from "../../../../src";
import { GQLiteralObject } from "../../../../src";

export const User = GQLitObject("User", t => {
export const User = GQLiteralObject("User", t => {
t.mix("Node");
});
2 changes: 1 addition & 1 deletion examples/swapi/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "gqlit-swapi-example",
"name": "gqliteral-swapi-example",
"version": "0.0.0",
"dependencies": {
"swapi-graphql": "^0.0.6"
Expand Down
40 changes: 24 additions & 16 deletions examples/swapi/src/schema/types/film.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
import { GQLitObject } from '../../../../../src';
import { GQLiteralObject } from "../../../../../src";

export const Film = GQLitObject('Film', t => {
t.description('A single film');
t.string('title', { description: 'The title of the film' });
t.int('episodeID', { description: 'The episode number of this film.', property: 'episode_id' });
t.string('openingCrawl', { description: 'The opening paragraphs at the beginning of this film.' });
t.string('director', { description: 'The name of the director of this film.' });
t.list('producers', 'String', {
description: 'The name(s) of the producer(s) of this film.',
export const Film = GQLiteralObject("Film", t => {
t.description("A single film");
t.string("title", { description: "The title of the film" });
t.int("episodeID", {
description: "The episode number of this film.",
property: "episode_id",
});
t.string("openingCrawl", {
description: "The opening paragraphs at the beginning of this film.",
});
t.string("director", {
description: "The name of the director of this film.",
});
t.list("producers", "String", {
description: "The name(s) of the producer(s) of this film.",
resolve: film => {
return film.producer.split(',').map((s: string) => s.trim());
return film.producer.split(",").map((s: string) => s.trim());
},
});
t.string('releaseDate', {
property: 'release_date',
description: 'The ISO 8601 date format of film release at original creator country.',
t.string("releaseDate", {
property: "release_date",
description:
"The ISO 8601 date format of film release at original creator country.",
});
t.field('speciesConnection', 'FilmSpeciesConnection');
t.field('starshipConnection', 'StarshipConnection');
t.field('starshipConnection', 'StarshipConnection');
t.field("speciesConnection", "FilmSpeciesConnection");
t.field("starshipConnection", "StarshipConnection");
t.field("starshipConnection", "StarshipConnection");
});
47 changes: 24 additions & 23 deletions examples/swapi/src/schema/types/person.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
import { GQLitObject } from '../../../../../src';
import { GQLiteralObject } from "../../../../../src";

export const Person = GQLitObject('Person', t => {
t.string('name', { description: 'The name of this person' });
t.string('birthYear', {
property: 'birth_year',
export const Person = GQLiteralObject("Person", t => {
t.string("name", { description: "The name of this person" });
t.string("birthYear", {
property: "birth_year",
description: `The birth year of the person, using the in-universe standard of BBY or ABY -
Before the Battle of Yavin or After the Battle of Yavin. The Battle of Yavin is
a battle that occurs at the end of Star Wars episode IV: A New Hope.`,
});
t.string('eyeColor', {
property: 'eye_color',
t.string("eyeColor", {
property: "eye_color",
description: `The eye color of this person. Will be "unknown" if not known or "n/a" if the
person does not have an eye.`,
});
t.string('gender', {
t.string("gender", {
description: `The gender of this person. Either "Male", "Female" or "unknown",
"n/a" if the person does not have a gender.`,
defaultValue: 'n/a',
defaultValue: "n/a",
});
t.string('hairColor', {
property: 'hair_color',
t.string("hairColor", {
property: "hair_color",
description: `The hair color of this person. Will be "unknown" if not known or "n/a" if the
person does not have hair.`,
});
t.int('height', {
t.int("height", {
resolve: person => convertToNumber(person.height),
description: 'The height of the person in centimeters.',
description: "The height of the person in centimeters.",
});
t.float('mass', {
t.float("mass", {
resolve: person => convertToNumber(person.mass),
description: 'The mass of the person in kilograms.',
description: "The mass of the person in kilograms.",
});
t.string('skinColor', {
property: 'skin_color',
description: 'The skin color of this person.',
t.string("skinColor", {
property: "skin_color",
description: "The skin color of this person.",
});
t.field('homeworld', 'Planet', {
resolve: person => (person.homeworld ? getObjectFromUrl(person.homeworld) : null),
description: 'A planet that this person was born on or inhabits.',
t.field("homeworld", "Planet", {
resolve: person =>
person.homeworld ? getObjectFromUrl(person.homeworld) : null,
description: "A planet that this person was born on or inhabits.",
});
});

/**
* Given a string, convert it to a number
*/
function convertToNumber(value: string): number | null {
if (['unknown', 'n/a'].indexOf(value) !== -1) {
if (["unknown", "n/a"].indexOf(value) !== -1) {
return null;
}
// remove digit grouping
const numberString = value.replace(/,/, '');
const numberString = value.replace(/,/, "");
return Number(numberString);
}

Expand Down
8 changes: 4 additions & 4 deletions examples/swapi/src/schema/types/planet.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GQLitObject } from '../../../../../src';
import { GQLiteralObject } from "../../../../../src";

export const Planet = GQLitObject('Planet', t => {
export const Planet = GQLiteralObject("Planet", t => {
t.description(`A large mass, planet or planetoid in the Star Wars Universe, at the time of
0 ABY.`);
t.string('name', { description: 'The name of this planet.' });
t.int('diameter');
t.string("name", { description: "The name of this planet." });
t.int("diameter");
});
23 changes: 13 additions & 10 deletions examples/swapi/src/schema/types/vehicle.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { GQLitObject } from '../../../../../src';
import { GQLiteralObject } from "../../../../../src";

export const Vehicle = GQLitObject('Vehicle', t => {
t.description('A single transport craft that does not have hyperdrive capability');
t.string('name', {
export const Vehicle = GQLiteralObject("Vehicle", t => {
t.description(
"A single transport craft that does not have hyperdrive capability"
);
t.string("name", {
description: `The name of this vehicle. The common name, such as "Sand Crawler" or "Speeder
bike".`,
});
t.string('model', {
t.string("model", {
description: `The model or official name of this vehicle. Such as "All-Terrain Attack
Transport".`,
});
t.string('vehicleClass', {
property: 'vehicle_class',
description: 'The class of this vehicle, such as "Wheeled" or "Repulsorcraft".',
t.string("vehicleClass", {
property: "vehicle_class",
description:
'The class of this vehicle, such as "Wheeled" or "Repulsorcraft".',
});
t.list('manufacturers', 'String', {
t.list("manufacturers", "String", {
// resolve: () => {},
description: 'The manufacturers of this vehicle.',
description: "The manufacturers of this vehicle.",
});
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "gqlit",
"name": "gqliteral",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
Expand All @@ -15,6 +15,7 @@
"husky": "^1.1.2",
"lint-staged": "^7.3.0",
"typescript": "^3.1.3",
"tslint": "^5.11.0",
"jest": "^23.6.0",
"ts-jest": "^23.10.4"
},
Expand Down
Loading

0 comments on commit b4b1ed5

Please sign in to comment.