Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
ee029b0
WIP relay pagination support
jneurock Jun 14, 2018
a8cf82e
Some bug fixing, unit testing WIP
jneurock Jun 21, 2018
0735671
more tests WIP
jneurock Jun 22, 2018
642080e
WIP add more unit tests
jneurock Jun 25, 2018
d04ac25
wip wip wip
jneurock Jun 27, 2018
c27a725
wipier wip
jneurock Aug 3, 2018
b469323
Fixup Add assertions to pagination test
jneurock Sep 11, 2018
9adbed5
improve module organization a litle bit
jneurock Sep 14, 2018
3ca99ff
fix root type mocking
jneurock Oct 2, 2018
01fd92d
remove some dead code
jneurock Oct 3, 2018
b84b031
improve fieldsMap and wip relay
jneurock Oct 3, 2018
d5e3b24
add rest for mock create
jneurock Oct 3, 2018
bf1ab33
Good WIP here. Almost there. I hope.
jneurock Dec 21, 2018
43ec5eb
organize modules better
jneurock Jan 5, 2019
8edef36
not sure about this commit at all
jneurock Jan 6, 2019
79382af
good WIP here
jneurock Jan 10, 2019
9cc57a3
try new, promising looking approach
jneurock Jan 11, 2019
3f584a4
first pass at an abstract tree of field info
jneurock Jan 11, 2019
0bf864c
getting closer now
jneurock Jan 14, 2019
3b6c4ee
re-implement recursive record fetching
jneurock Jan 14, 2019
25a8d34
fix issue fetching node records
jneurock Jan 16, 2019
6c52c6d
started with filtering in the new style
jneurock Jan 18, 2019
98c37f0
progress on filtering
jneurock Jan 21, 2019
c92b059
fixed filtering issue
jneurock Jan 21, 2019
58f00f3
filter by mapped field works, interface typehas issues
jneurock Jan 22, 2019
131f8f6
something is working now
jneurock Jan 22, 2019
ff5ff91
oh, it's getting so close now
jneurock Jan 23, 2019
cfd3d81
interface types resolve now
jneurock Jan 23, 2019
0f2c955
progress on fixing related records mapping bug
jneurock Jan 23, 2019
4a6dc2b
fixed field mapping issues
jneurock Jan 23, 2019
7bfce63
tests are passing!!!
jneurock Jan 23, 2019
cf471f0
clean up code
jneurock Jan 24, 2019
05e0bbf
add test for string type variable mapping
jneurock Jan 24, 2019
72983c9
add test for root query returning scalar value
jneurock Jan 24, 2019
4196d64
added tests for utils
jneurock Jan 24, 2019
9ba8e7b
added unit test for db
jneurock Jan 24, 2019
562310a
added unit test for field args
jneurock Jan 24, 2019
fbfdc75
added test for field names
jneurock Jan 24, 2019
1982cf0
make minor code style tweak
jneurock Jan 24, 2019
2cea09e
clean up a little code
jneurock Jan 25, 2019
774b2cd
added test for field types
jneurock Jan 25, 2019
3c16c07
added unit test for field selections
jneurock Jan 25, 2019
2399ba4
upgraded Ember version
jneurock Jan 25, 2019
8d290a5
refactor out RouteQueryManager from test routes
jneurock Jan 25, 2019
38a17cd
update deps
jneurock Jan 25, 2019
12c0ce9
update Travis config
jneurock Jan 25, 2019
6bace5e
rollback Mirage one patch version
jneurock Jan 25, 2019
56c942b
lock down Mirage version
jneurock Jan 25, 2019
66ca858
rollback Mirage version to 0.4.7
jneurock Jan 25, 2019
05c6b99
remove webpack stuff now that we have ember-auto-import
jneurock Jan 25, 2019
7af9ea9
add missing ember-try config
jneurock Jan 25, 2019
c2154b8
added some unit tests for fields and filters
jneurock Jan 26, 2019
3ad0c9c
add unit test for parent filter
jneurock Jan 28, 2019
41bfeec
added some filtering unit test but they need more work
jneurock Jan 28, 2019
ec2478e
add more filter and relay unit tests
jneurock Jan 29, 2019
6691573
start adding unit test for field mapping
jneurock Jan 31, 2019
66a1219
finish adding unit tests for field mapping
jneurock Jan 31, 2019
8c7c657
add unit tests for relay and interface types
jneurock Feb 1, 2019
ea7b126
add some TODOs
jneurock Feb 3, 2019
01c8332
start unit tests for field info
jneurock Feb 4, 2019
b92adaf
finish unit tests for field info
jneurock Feb 4, 2019
b9b5020
test field mapping better
jneurock Feb 5, 2019
785b418
started adding unit tests for fields/records
jneurock Feb 6, 2019
0971eb6
start refactoring filters for better testing
jneurock Feb 7, 2019
e20201c
started refactoring field map stuff
jneurock Feb 8, 2019
94ec482
update unit tests for records fields mapping
jneurock Feb 8, 2019
8db00a1
refactor more composable functions and unit tests
jneurock Feb 8, 2019
4cdfd56
add unit tests for getting records
jneurock Feb 10, 2019
77bff5c
refactor unit tests for field selections
jneurock Feb 10, 2019
e64ea11
refactor field selections and type unit tests
jneurock Feb 11, 2019
d811943
refactor filter application and unit tests
jneurock Feb 11, 2019
680253c
refactored filter creation and unit tests
jneurock Feb 11, 2019
bd5e319
start refactoring parent filters and unit tests
jneurock Feb 11, 2019
196d666
finish refactoring parent filters and unit tests
jneurock Feb 11, 2019
f7fadb3
refactor mocking functions
jneurock Feb 12, 2019
3cd3f99
add unit tests for query mocking
jneurock Feb 12, 2019
0fabab3
add unit tests for mutations mocking
jneurock Feb 12, 2019
2e0b7b1
refactor realy edges functions and tests
jneurock Feb 13, 2019
5ea9c96
refactor relay filter functions and unit tests
jneurock Feb 13, 2019
b80fada
add unit tests for records
jneurock Feb 13, 2019
a7c0f80
refactor interface type resolvers and unit tests
jneurock Feb 13, 2019
a48d6d4
added unit test for db function
jneurock Feb 13, 2019
8c5ea95
add unit test for creating the handler
jneurock Feb 13, 2019
fa24f42
add unit test for schema functions
jneurock Feb 13, 2019
c5822db
add code coverage
jneurock Feb 13, 2019
ec563ad
add coveralls to travis config
jneurock Feb 14, 2019
584575d
exclude addon from builds per Mirage config
jneurock Feb 14, 2019
143a226
add support for fragments
jneurock Feb 15, 2019
5f50315
fix usage of alias in field info
jneurock Feb 16, 2019
7ddb245
parent records are allowed to be null
jneurock Feb 17, 2019
e6b5a1c
fix issues with root level aliases
jneurock Feb 17, 2019
3c16121
return caught errors when mocking queries
jneurock Feb 17, 2019
1f5b224
fix issue with resolving relay page info
jneurock Feb 19, 2019
f61792a
add util for adding __typename fields to objects
jneurock Feb 19, 2019
6493c17
fix version number and update graphql deps
jneurock Feb 20, 2019
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
21 changes: 20 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
/blueprints/*/files/**/*.js
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
7 changes: 5 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
globals: {
server: true,
server: true
},
root: true,
parserOptions: {
Expand All @@ -23,12 +23,15 @@ module.exports = {
// node files
{
files: [
'.eslintrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
'index.js',
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'tests/dummy/config/**/*.js'
'tests/dummy/config/**/*.js',
'lib/**/*.js'
],
excludedFiles: [
'addon/**',
Expand Down
24 changes: 13 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp
/dist/
/tmp/

# dependencies
/node_modules
/bower_components
/bower_components/
/node_modules/

# misc
/.coveralls*
/.env*
/.sass-cache
/connect.lock
/coverage/*
/coverage/
/libpeerconnection.log
npm-debug.log*
yarn-error.log
testem.log
/npm-debug.log*
/testem.log
/yarn-error.log

# ember-try
.node_modules.ember-try/
bower.json.ember-try
package.json.ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
46 changes: 28 additions & 18 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
/bower_components
# compiled output
/dist/
/tmp/

# dependencies
/bower_components/

# misc
/.bowerrc
/.editorconfig
/.ember-cli
/.env*
/.eslintignore
/.eslintrc.js
/.gitignore
/.template-lintrc.js
/.travis.yml
/.watchmanconfig
/bower.json
/config/ember-try.js
/dist
/tests
/tmp
**/.gitkeep
.bowerrc
.editorconfig
.ember-cli
.eslintrc.js
.gitignore
.watchmanconfig
.travis.yml
bower.json
ember-cli-build.js
testem.js
/CONTRIBUTING.md
/ember-cli-build.js
/testem.js
/tests/
/yarn.lock
.gitkeep

# ember-try
.node_modules.ember-try/
bower.json.ember-try
package.json.ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
5 changes: 5 additions & 0 deletions .template-lintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
extends: 'recommended'
};
59 changes: 37 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,52 @@ addons:
chrome: stable

cache:
yarn: true
directories:
- $HOME/.npm

env:
global:
# See https://git.io/vdao3 for details.
- JOBS=1
matrix:

# TODO: Revisit this later in case we do want to limit Travis builds
# branches:
# only:
# - master
# # npm version tags
# - /^v\d+\.\d+\.\d+/

jobs:
fail_fast: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary

include:
# runs linting and tests with current locked deps

- stage: "Tests"
name: "Tests"
script:
- npm run lint:hbs
- npm run lint:js
- npm test
- cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js

# we recommend new addons test the current and previous LTS
# as well as latest stable release (bonus points to beta/canary)
- EMBER_TRY_SCENARIO=ember-lts-2.12
- EMBER_TRY_SCENARIO=ember-lts-2.16
- EMBER_TRY_SCENARIO=ember-lts-2.18
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
- EMBER_TRY_SCENARIO=ember-default

matrix:
fast_finish: true
allow_failures:
- stage: "Additional Tests"
env: EMBER_TRY_SCENARIO=ember-lts-2.16
- env: EMBER_TRY_SCENARIO=ember-lts-2.18
- env: EMBER_TRY_SCENARIO=ember-lts-3.4
- env: EMBER_TRY_SCENARIO=ember-release
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary
- env: EMBER_TRY_SCENARIO=ember-default-with-jquery

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH

install:
- yarn install --no-lockfile --non-interactive
- npm config set spin false
- npm install -g npm@4
- npm --version

script:
- yarn lint:js
# Usually, it's ok to finish the test scenario without reverting
# to the addon's original dependency state, skipping "cleanup".
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO --skip-cleanup
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# How To Contribute

## Installation

* `git clone <repository-url>`
* `cd my-addon`
* `npm install`

## Linting

* `npm run lint:hbs`
* `npm run lint:js`
* `npm run lint:js -- --fix`

## Running tests

* `ember test` – Runs the test suite on the current Ember version
* `ember test --server` – Runs the test suite in "watch mode"
* `ember try:each` – Runs the test suite against multiple Ember versions

## Running the dummy application

* `ember serve`
* Visit the dummy application at [http://localhost:4200](http://localhost:4200).

For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2019 kloeckner-i GmbH

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.
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

This addon is for mocking GraphQL with Ember CLI Mirage.

## Compatibility

* Ember.js v2.18 or above
* Ember CLI v2.13 or above

## Note

This addon is very early in its development and the code currently supports limited use cases. If you would like to contribute, don't be afraid to trample any existing code. It's quite trampleable.
Expand Down Expand Up @@ -63,7 +68,7 @@ You may pass in options when creating a request handler. The options take the fo
```javascript
{
/*
fieldsMap is used if you need to map a field defined in your
`fieldsMap` is used if you need to map a field defined in your
GraphQL schema to a different field for a record in your Mirage
database.

Expand All @@ -76,29 +81,34 @@ You may pass in options when creating a request handler. The options take the fo
String values will be used to map field names from your query to
match those in your Mirage database.

Function values will be used to filter records and will run after
Method values will be used to filter records and will run after
any variable filtering and related data fetching. This allows for
complex record filtering that can't be done with variables alone.
The methods receive 3 arguments:

1. The resolved records, if any.
2. Mirage's database.
3. Its parent record, if any.
*/
fieldsMap: {
Person: { // fields are mapped on a per-type basis
pets: 'animals'
}
},
/*
mutations is an object used to mock mutation functionality you might expect
from the server. Each method maps directly to a named mutation from your
schema and accepts 3 arguments:

1. The table from Mirage's database that corresponds to the return type of
the mutation.
2. The mutation variables. These will be mapped per the varsMap option, by
the return type, if appropriate.
`mutations` is an object used to mock mutation functionality you
might expect from the server. Each method maps directly to a
named mutation from your schema and receives 3 arguments:

1. The table from Mirage's database that corresponds to the return
type of the mutation.
2. The mutation variables. These will be mapped per the varsMap
option, by the return type, if appropriate.
3. Mirage's database.

For now, this is the only way to mock mutations with this addon; however, we
will try to implement some form of default mutation functionality, if
feasible.
For now, this is the only way to mock mutations with this addon;
however, we will try to implement some form of default mutation
functionality, if feasible.
*/
mutations: {
updatePerson: (people, vars, db) => {
Expand Down
16 changes: 16 additions & 0 deletions addon/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { camelize, pluralize } from 'ember-cli-mirage/utils/inflector';
import { getMappedFieldNameByParentType } from './fields/name/map';

export const getTableName = (typeName) => camelize(pluralize(typeName));

export const composeGetRecords = (getTableName) =>
(db, typeName) => db[getTableName(typeName)];

export const getRecords = composeGetRecords(getTableName);

export const composeGetTableNameForField = (getMappedFieldName, getTableName) =>
(fieldName, parent, typeName, fieldsMap) =>
getMappedFieldName(fieldName, parent, fieldsMap) || getTableName(typeName);

export const getTableNameForField =
composeGetTableNameForField(getMappedFieldNameByParentType, getTableName);
6 changes: 6 additions & 0 deletions addon/fields/args.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const getArgsForField = (field) =>
field.arguments.map(({ name, value }) => ({
kind: value.kind,
name: value.name && value.name.value || name.value,
value: value.value
}));
Loading