Skip to content

Commit

Permalink
fix queries (parse-community#6363)
Browse files Browse the repository at this point in the history
  • Loading branch information
Moumouls authored and davimacedo committed Jan 28, 2020
1 parent 8ee829f commit 82bf481
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 7 deletions.
109 changes: 109 additions & 0 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9980,6 +9980,87 @@ describe('ParseGraphQLServer', () => {
expect(typeof getResult.data.someClass.someField).toEqual('object');
expect(getResult.data.someClass.someField).toEqual(someFieldValue);
expect(getResult.data.someClasses.edges.length).toEqual(1);

const getGeoWhere = await apolloClient.query({
query: gql`
query GeoQuery($latitude: Float!, $longitude: Float!) {
nearSphere: someClasses(
where: {
someField: {
nearSphere: {
latitude: $latitude
longitude: $longitude
}
}
}
) {
edges {
node {
id
}
}
}
geoWithin: someClasses(
where: {
someField: {
geoWithin: {
centerSphere: {
distance: 10
center: {
latitude: $latitude
longitude: $longitude
}
}
}
}
}
) {
edges {
node {
id
}
}
}
within: someClasses(
where: {
someField: {
within: {
box: {
bottomLeft: {
latitude: $latitude
longitude: $longitude
}
upperRight: {
latitude: $latitude
longitude: $longitude
}
}
}
}
}
) {
edges {
node {
id
}
}
}
}
`,
variables: {
latitude: 45,
longitude: 45,
},
});
expect(getGeoWhere.data.nearSphere.edges[0].node.id).toEqual(
createResult.data.createSomeClass.someClass.id
);
expect(getGeoWhere.data.geoWithin.edges[0].node.id).toEqual(
createResult.data.createSomeClass.someClass.id
);
expect(getGeoWhere.data.within.edges[0].node.id).toEqual(
createResult.data.createSomeClass.someClass.id
);
} catch (e) {
handleError(e);
}
Expand Down Expand Up @@ -10078,6 +10159,34 @@ describe('ParseGraphQLServer', () => {
}))
);
expect(getResult.data.someClasses.edges.length).toEqual(1);
const getIntersect = await apolloClient.query({
query: gql`
query IntersectQuery($point: GeoPointInput!) {
someClasses(
where: {
somePolygonField: { geoIntersects: { point: $point } }
}
) {
edges {
node {
id
somePolygonField {
latitude
longitude
}
}
}
}
}
`,
variables: {
point: { latitude: 44, longitude: 45 },
},
});
expect(getIntersect.data.someClasses.edges.length).toEqual(1);
expect(getIntersect.data.someClasses.edges[0].node.id).toEqual(
createResult.data.createSomeClass.someClass.id
);
} catch (e) {
handleError(e);
}
Expand Down
18 changes: 11 additions & 7 deletions src/GraphQL/transformers/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,17 @@ const transformQueryConstraintInputToParse = (
return;
}
switch (fieldName) {
case '$point':
case '$nearSphere':
case 'point':
if (typeof fieldValue === 'object' && !fieldValue.__type) {
fieldValue.__type = 'GeoPoint';
}
break;
case '$box':
case 'nearSphere':
if (typeof fieldValue === 'object' && !fieldValue.__type) {
fieldValue.__type = 'GeoPoint';
}
break;
case 'box':
if (
typeof fieldValue === 'object' &&
fieldValue.bottomLeft &&
Expand All @@ -204,10 +208,10 @@ const transformQueryConstraintInputToParse = (
...fieldValue.upperRight,
},
];
constraints[fieldName] = fieldValue;
constraints[parseConstraintMap[fieldName]] = fieldValue;
}
break;
case '$polygon':
case 'polygon':
if (fieldValue instanceof Array) {
fieldValue.forEach(geoPoint => {
if (typeof geoPoint === 'object' && !geoPoint.__type) {
Expand All @@ -216,7 +220,7 @@ const transformQueryConstraintInputToParse = (
});
}
break;
case '$centerSphere':
case 'centerSphere':
if (
typeof fieldValue === 'object' &&
fieldValue.center &&
Expand All @@ -229,7 +233,7 @@ const transformQueryConstraintInputToParse = (
},
fieldValue.distance,
];
constraints[fieldName] = fieldValue;
constraints[parseConstraintMap[fieldName]] = fieldValue;
}
break;
}
Expand Down

0 comments on commit 82bf481

Please sign in to comment.