Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit ef77cd2

Browse files
committed
Fix issues
1 parent 9603f4f commit ef77cd2

13 files changed

+68
-30
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
}],
66
"stage-3"
77
],
8-
"plugins": ["add-module-exports"]
8+
"plugins": ["add-module-exports", "transform-runtime"]
99
}

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
22
"name": "parse-server-graphql",
33
"version": "0.0.0",
4-
"main": "index.js",
4+
"main": "lib/index.js",
55
"author": "stephentuso",
66
"license": "MIT",
77
"scripts": {
8-
"build": "babel src -d lib"
8+
"build": "babel src -d lib",
9+
"prepublishOnly": "npm run build"
910
},
1011
"dependencies": {
1112
"axios": "^0.18.0",
13+
"babel-runtime": "^6.26.0",
1214
"express-graphql": "^0.6.12",
1315
"graphql": "^0.13.1",
1416
"graphql-list-fields": "^2.0.1",
@@ -19,6 +21,7 @@
1921
"devDependencies": {
2022
"babel-cli": "^6.26.0",
2123
"babel-plugin-add-module-exports": "^0.2.1",
24+
"babel-plugin-transform-runtime": "^6.23.0",
2225
"babel-preset-env": "^1.6.1",
2326
"babel-preset-stage-3": "^6.24.1"
2427
}

src/baseMapping.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { mapValues, constant } from 'lodash/fp';
2+
import JSON from 'graphql-type-json';
23
import File from './types/File';
34
import Date from './types/Date';
45
import ACL from './types/ACL';
@@ -8,11 +9,15 @@ import {
89
GraphQLFloat,
910
} from 'graphql';
1011

11-
export default mapValues(constant, {
12-
File,
13-
Date,
14-
ACL,
15-
String: GraphQLString,
16-
Boolean: GraphQLBoolean,
17-
Number: GraphQLFloat,
18-
});
12+
export default {
13+
...mapValues(constant, {
14+
File,
15+
Date,
16+
ACL,
17+
Object: JSON,
18+
String: GraphQLString,
19+
Boolean: GraphQLBoolean,
20+
Number: GraphQLFloat,
21+
}),
22+
Pointer: ({ targetClass }, mapping) => mapping[targetClass](),
23+
};

src/fetchParseSchema.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import axios from 'axios';
22
import { get } from 'lodash';
33

4-
export default async function fetchParseSchema({ serverUrl, appId, masterKey }) {
4+
export default async function fetchParseSchema({ serverURL, appId, masterKey }) {
55
const response = await axios({
66
method: 'get',
7-
url: `${serverUrl}/schemas`,
7+
url: `${serverURL}/schemas`,
88
headers: {
99
'X-Parse-Application-Id': appId,
1010
'X-Parse-Master-Key': masterKey,

src/generateSchema.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1-
import { mapValues } from 'lodash';
1+
import { flow, reduce, mapValues } from 'lodash/fp';
22
import { GraphQLSchema, GraphQLObjectType } from 'graphql';
33
import typeForClass from './typeForClass';
44
import dependencyHelper from './utils/dependencyHelper';
55
import baseMapping from './baseMapping';
6-
import queryForType from './queryForType'
6+
import queryForType from './queryForType';
77

88
export default function generateSchema(parseSchema) {
99
const types = dependencyHelper(
1010
baseMapping,
11-
mapValues(parseSchema, typeForClass),
11+
flow(
12+
reduce((obj, data) => ({
13+
...obj,
14+
[data.className]: data,
15+
}), {}),
16+
mapValues(typeForClass),
17+
)(parseSchema),
1218
);
1319

20+
console.log(types);
21+
1422
const queryFields = parseSchema.reduce((acc, { className }) => ({
1523
...acc,
16-
[className]: queryForType(types[className]),
24+
[className]: queryForType(className, types[className]()),
1725
}), {});
1826

1927
const query = new GraphQLObjectType({

src/index.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
import graphqlHTTP from 'express-graphql';
22
import generateSchema from './generateSchema';
33
import fetchParseSchema from './fetchParseSchema';
4+
import Parse from 'parse/node';
5+
6+
console.log('TEST');
47

58
const getSchema = (() => {
69
let schema;
710
return async (options, alwaysRecreate) => {
811
if (!schema || alwaysRecreate) {
912
schema = generateSchema(await fetchParseSchema(options));
1013
}
14+
console.log(schema);
1115
return schema;
1216
}
13-
});
17+
})();
1418

1519
export default function parseGraphQL(options) {
16-
return graphqlHTTP(async () => ({
17-
schema: await getSchema(options, options.dynamicSchema),
18-
graphiql: true,
19-
}));
20+
Parse.initialize(options.appId);
21+
Parse.serverURL = options.serverURL;
22+
return graphqlHTTP(async () => {
23+
try {
24+
return ({
25+
schema: await getSchema(options, options.dynamicSchema),
26+
graphiql: true,
27+
});
28+
} catch (e) {
29+
console.error(e);
30+
}
31+
});
2032
};

src/mapType.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import JSON from 'graphql-type-json';
2+
13
export default function mapType({ type, ...params }, mapping) {
2-
return mapping[type](params);
4+
console.log(type, params);
5+
const getType = mapping[type];
6+
return getType ? getType(params, mapping) : JSON;
37
}

src/queryForType.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import JSON from 'graphql-type-json';
33
import getFieldNames from 'graphql-list-fields';
44
import Parse from 'parse/node';
55

6-
export default (Type) => ({
6+
export default (parseClass, Type) => ({
77
type: GraphQLList(Type),
88
args: {
99
json: {
@@ -12,7 +12,7 @@ export default (Type) => ({
1212
},
1313
resolve(_, { json }, context, info) {
1414
const fields = getFieldNames(info);
15-
const query = Parse.Query.from(json);
15+
const query = Parse.Query.fromJSON(parseClass, { ...json } || { where: {} });
1616
fields.forEach(field => query.include(field));
1717
return query.find();
1818
}

src/typeForClass.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { GraphQLObjectType } from 'graphql';
22
import JSON from 'graphql-type-json';
33
import { mapValues } from 'lodash';
4-
import { property } from 'lodash/fp';
4+
import { property, constant } from 'lodash/fp';
55
import mapType from './mapType';
66

77
const specialResolvers = {
@@ -13,7 +13,7 @@ const specialResolvers = {
1313

1414
const standardResolver = key => item => item.get(key);
1515

16-
export default ({ className, fields }) => (typeMap) => () => {
16+
export default ({ className, fields }) => (typeMap) => constant((() => {
1717
const propertyFields = () => mapValues(fields, (data, key) => ({
1818
type: mapType(data, typeMap),
1919
resolve: specialResolvers[key] || standardResolver(key),
@@ -29,4 +29,4 @@ export default ({ className, fields }) => (typeMap) => () => {
2929
},
3030
}),
3131
});
32-
};
32+
})());

src/types/Date.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { GraphQLScalarType } from 'graphql';
22
import { Kind } from 'graphql/language';
3-
import moment from 'moment';
4-
import { identity } from 'lodash';
53

64
const parseValue = dateString => new Date(dateString);
75

src/utils/defineLazyProperty.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function defineLazyProperty(object, key, valueFunc) {
1616
enumerable: true,
1717
value: valueFunc(),
1818
});
19+
console.log(key, this[key]);
1920
return this[key];
2021
},
2122
});

src/utils/dependencyHelper.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function dependencyHelper(defaultData, initializerMap) {
1818
key,
1919
() => initializerMap[key](dependencies)
2020
);
21+
return dependencies;
2122
}, { ...defaultData });
2223
}
2324

yarn.lock

+6
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,12 @@ babel-plugin-transform-regenerator@^6.22.0:
507507
dependencies:
508508
regenerator-transform "^0.10.0"
509509

510+
babel-plugin-transform-runtime@^6.23.0:
511+
version "6.23.0"
512+
resolved "https://registry.yarnpkg.com/babel-plugin-transform-runtime/-/babel-plugin-transform-runtime-6.23.0.tgz#88490d446502ea9b8e7efb0fe09ec4d99479b1ee"
513+
dependencies:
514+
babel-runtime "^6.22.0"
515+
510516
babel-plugin-transform-strict-mode@^6.24.1:
511517
version "6.24.1"
512518
resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758"

0 commit comments

Comments
 (0)