Skip to content

Commit

Permalink
Add various repo files and fix ported implementation
Browse files Browse the repository at this point in the history
* upstream comments added to each file
* added temporary module for polyfills until the features are merged
  into master, then this module can be removed and replaced with the
  rotriever package.
  • Loading branch information
RoFlection Bot committed Nov 17, 2020
1 parent 6977e17 commit d66cb95
Show file tree
Hide file tree
Showing 40 changed files with 591 additions and 72 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*.lua]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false

[*.json]
indent_style = spaces
indent_width = 2
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/*.rbxmx
/*.sig
/rotriever.lock
/Packages
Packages/*
!Packages/.robloxrc
.DS_Store
.vscode
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) GraphQL Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions Packages/.robloxrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"language": {
"mode": "nocheck"
},
"lint": {
"*": "disabled"
}
}
167 changes: 167 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# GraphQL.lua

The JavaScript reference implementation for GraphQL, a query language for APIs created by Facebook.

[![npm version](https://badge.fury.io/js/graphql.svg)](https://badge.fury.io/js/graphql)
[![Build Status](https://github.com/graphql/graphql-js/workflows/CI/badge.svg?branch=master)](https://github.com/graphql/graphql-js/actions?query=branch%3Amaster)
[![Coverage Status](https://codecov.io/gh/graphql/graphql-js/branch/master/graph/badge.svg)](https://codecov.io/gh/graphql/graphql-js)

See more complete documentation at https://graphql.org/ and
https://graphql.org/graphql-js/.

Looking for help? Find resources [from the community](https://graphql.org/community/).

## Getting Started

A general overview of GraphQL is available in the
[README](https://github.com/graphql/graphql-spec/blob/master/README.md) for the
[Specification for GraphQL](https://github.com/graphql/graphql-spec). That overview
describes a simple set of GraphQL examples that exist as [tests](src/__tests__)
in this repository. A good way to get started with this repository is to walk
through that README and the corresponding tests in parallel.

### Using GraphQL.js

Install GraphQL.js from npm

With npm:

```sh
npm install --save graphql
```

or using yarn:

```sh
yarn add graphql
```

GraphQL.js provides two important capabilities: building a type schema and
serving queries against that type schema.

First, build a GraphQL type schema which maps to your codebase.

```js
import {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
} from 'graphql';

var schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
hello: {
type: GraphQLString,
resolve() {
return 'world';
},
},
},
}),
});
```

This defines a simple schema, with one type and one field, that resolves
to a fixed value. The `resolve` function can return a value, a promise,
or an array of promises. A more complex example is included in the top-level [tests](src/__tests__) directory.

Then, serve the result of a query against that type schema.

```js
var query = '{ hello }';

graphql(schema, query).then((result) => {
// Prints
// {
// data: { hello: "world" }
// }
console.log(result);
});
```

This runs a query fetching the one field defined. The `graphql` function will
first ensure the query is syntactically and semantically valid before executing
it, reporting errors otherwise.

```js
var query = '{ BoyHowdy }';

graphql(schema, query).then((result) => {
// Prints
// {
// errors: [
// { message: 'Cannot query field BoyHowdy on RootQueryType',
// locations: [ { line: 1, column: 3 } ] }
// ]
// }
console.log(result);
});
```

**Note**: Please don't forget to set `NODE_ENV=production` if you are running a production server. It will disable some checks that can be useful during development but will significantly improve performance.

### Want to ride the bleeding edge?

The `npm` branch in this repository is automatically maintained to be the last
commit to `master` to pass all tests, in the same form found on npm. It is
recommended to use builds deployed to npm for many reasons, but if you want to use
the latest not-yet-released version of graphql-js, you can do so by depending
directly on this branch:

```
npm install graphql@git://github.com/graphql/graphql-js.git#npm
```

### Using in a Browser

GraphQL.js is a general-purpose library and can be used both in a Node server
and in the browser. As an example, the [GraphiQL](https://github.com/graphql/graphiql/)
tool is built with GraphQL.js!

Building a project using GraphQL.js with [webpack](https://webpack.js.org) or
[rollup](https://github.com/rollup/rollup) should just work and only include
the portions of the library you use. This works because GraphQL.js is distributed
with both CommonJS (`require()`) and ESModule (`import`) files. Ensure that any
custom build configurations look for `.mjs` files!

### Contributing

We actively welcome pull requests. Learn how to [contribute](./.github/CONTRIBUTING.md).

### Changelog

Changes are tracked as [GitHub releases](https://github.com/graphql/graphql-js/releases).

### License

GraphQL.js is [MIT-licensed](./LICENSE).

### Credits

The `*.d.ts` files in this project are based on [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/54712a7e28090c5b1253b746d1878003c954f3ff/types/graphql) definitions written by:

<!--- spell-checker:disable -->

- TonyYang https://github.com/TonyPythoneer
- Caleb Meredith https://github.com/calebmer
- Dominic Watson https://github.com/intellix
- Firede https://github.com/firede
- Kepennar https://github.com/kepennar
- Mikhail Novikov https://github.com/freiksenet
- Ivan Goncharov https://github.com/IvanGoncharov
- Hagai Cohen https://github.com/DxCx
- Ricardo Portugal https://github.com/rportugal
- Tim Griesser https://github.com/tgriesser
- Dylan Stewart https://github.com/dyst5422
- Alessio Dionisi https://github.com/adnsio
- Divyendu Singh https://github.com/divyenduz
- Brad Zacher https://github.com/bradzacher
- Curtis Layne https://github.com/clayne11
- Jonathan Cardoso https://github.com/JCMais
- Pavel Lang https://github.com/langpavel
- Mark Caudill https://github.com/mc0
- Martijn Walraven https://github.com/martijnwalraven
- Jed Mao https://github.com/jedmao
Empty file removed rbx-aged-tool.log
Empty file.
1 change: 1 addition & 0 deletions rotriever.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ author = "Roblox"
content_root = "src"

[dependencies]
LuauPolyfill = { git = "https://github.com/Roblox/luau-polyfill.git", rev = "main" }

[dev_dependencies]
TestEZ = "github.com/roblox/[email protected]"
2 changes: 1 addition & 1 deletion scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -ex

rojo build test-bundle.project.json --output graphql.rbxmx

roblox-cli analyze default.project.json
roblox-cli analyze test-bundle.project.json
roblox-cli run --load.model graphql.rbxmx --run scripts/spec.lua
104 changes: 104 additions & 0 deletions src/TestMatchers/__tests__/toEqual.spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
return function()
local toEqual = require(script.Parent.Parent.toEqual)

it("should fail with a message when args are not equal", function()
local result = toEqual(1, 2)

expect(result.pass).to.equal(false)
expect(result.message).to.equal("received (1) ~= expected (2)")

result = toEqual({
foo = 1,
}, {
foo = 2,
})

expect(result.pass).to.equal(false)
expect(result.message:find("received%[foo%] %(1%) ~= expected%[foo%] %(2%)")).to.be.ok()
end)

it("should compare non-table values using standard '==' equality", function()
assert(toEqual(1, 1).pass)
assert(toEqual("hello", "hello").pass)
assert(toEqual(nil, nil).pass)

local someFunction = function() end
local theSameFunction = someFunction

assert(toEqual(someFunction, theSameFunction).pass)

local A = {
foo = someFunction
}
local B = {
foo = theSameFunction
}

assert(toEqual(A, B).pass)
end)

it("should fail when types differ", function()
local result = toEqual(1, "1")

expect(result.pass).to.equal(false)
expect(result.message).to.equal("received: value of type 'number'\nexpected: value of type 'string'")
end)

it("should compare (and report about) nested tables", function()
local A = {
foo = "bar",
nested = {
foo = 1,
bar = 2,
}
}
local B = {
foo = "bar",
nested = {
foo = 1,
bar = 2,
}
}

assert(toEqual(A, B).pass)

local C = {
foo = "bar",
nested = {
foo = 1,
bar = 3,
}
}

local result = toEqual(A, C)

expect(result.pass).to.equal(false)
expect(result.message:find("received%[nested%]%[bar%] %(2%) ~= expected%[nested%]%[bar%] %(3%)")).to.be.ok()
end)

it("should be commutative", function()
local equalArgsA = {
foo = "bar",
hello = "world",
}
local equalArgsB = {
foo = "bar",
hello = "world",
}

assert(toEqual(equalArgsA, equalArgsB).pass)
assert(toEqual(equalArgsB, equalArgsA).pass)

local nonEqualArgs = {
foo = "bar",
}

local result = toEqual(equalArgsA, nonEqualArgs)
assert(not result.pass)
expect(result.message:find("received%[hello%] ~= expected%[hello%]"))

result = toEqual(nonEqualArgs, equalArgsA)
assert(not result.pass)
expect(result.message:find("received%[hello%] ~= expected%[hello%]"))
end)
end
Loading

0 comments on commit d66cb95

Please sign in to comment.