fix queries (#6363)

This commit is contained in:
Antoine Cormouls
2020-01-28 04:10:39 +01:00
committed by Antonio Davi Macedo Coelho de Castro
parent d4e264daf8
commit df3fa029bc
2 changed files with 120 additions and 7 deletions

View File

@@ -9980,6 +9980,87 @@ describe('ParseGraphQLServer', () => {
expect(typeof getResult.data.someClass.someField).toEqual('object'); expect(typeof getResult.data.someClass.someField).toEqual('object');
expect(getResult.data.someClass.someField).toEqual(someFieldValue); expect(getResult.data.someClass.someField).toEqual(someFieldValue);
expect(getResult.data.someClasses.edges.length).toEqual(1); 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) { } catch (e) {
handleError(e); handleError(e);
} }
@@ -10078,6 +10159,34 @@ describe('ParseGraphQLServer', () => {
})) }))
); );
expect(getResult.data.someClasses.edges.length).toEqual(1); 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) { } catch (e) {
handleError(e); handleError(e);
} }

View File

@@ -182,13 +182,17 @@ const transformQueryConstraintInputToParse = (
return; return;
} }
switch (fieldName) { switch (fieldName) {
case '$point': case 'point':
case '$nearSphere':
if (typeof fieldValue === 'object' && !fieldValue.__type) { if (typeof fieldValue === 'object' && !fieldValue.__type) {
fieldValue.__type = 'GeoPoint'; fieldValue.__type = 'GeoPoint';
} }
break; break;
case '$box': case 'nearSphere':
if (typeof fieldValue === 'object' && !fieldValue.__type) {
fieldValue.__type = 'GeoPoint';
}
break;
case 'box':
if ( if (
typeof fieldValue === 'object' && typeof fieldValue === 'object' &&
fieldValue.bottomLeft && fieldValue.bottomLeft &&
@@ -204,10 +208,10 @@ const transformQueryConstraintInputToParse = (
...fieldValue.upperRight, ...fieldValue.upperRight,
}, },
]; ];
constraints[fieldName] = fieldValue; constraints[parseConstraintMap[fieldName]] = fieldValue;
} }
break; break;
case '$polygon': case 'polygon':
if (fieldValue instanceof Array) { if (fieldValue instanceof Array) {
fieldValue.forEach(geoPoint => { fieldValue.forEach(geoPoint => {
if (typeof geoPoint === 'object' && !geoPoint.__type) { if (typeof geoPoint === 'object' && !geoPoint.__type) {
@@ -216,7 +220,7 @@ const transformQueryConstraintInputToParse = (
}); });
} }
break; break;
case '$centerSphere': case 'centerSphere':
if ( if (
typeof fieldValue === 'object' && typeof fieldValue === 'object' &&
fieldValue.center && fieldValue.center &&
@@ -229,7 +233,7 @@ const transformQueryConstraintInputToParse = (
}, },
fieldValue.distance, fieldValue.distance,
]; ];
constraints[fieldName] = fieldValue; constraints[parseConstraintMap[fieldName]] = fieldValue;
} }
break; break;
} }