Introduce ReadOptionsInput (#6030)

This commit is contained in:
Antonio Davi Macedo Coelho de Castro
2019-09-12 13:43:49 -07:00
committed by GitHub
parent 63cabb8423
commit 1361bb3020
4 changed files with 97 additions and 67 deletions

View File

@@ -483,6 +483,22 @@ const SUBQUERY_READ_PREFERENCE_ATT = {
type: READ_PREFERENCE,
};
const READ_OPTIONS_INPUT = new GraphQLInputObjectType({
name: 'ReadOptionsInput',
description:
'The ReadOptionsInputt type is used in queries in order to set the read preferences.',
fields: {
readPreference: READ_PREFERENCE_ATT,
includeReadPreference: INCLUDE_READ_PREFERENCE_ATT,
subqueryReadPreference: SUBQUERY_READ_PREFERENCE_ATT,
},
});
const READ_OPTIONS_ATT = {
description: 'The read options for the query to be executed.',
type: READ_OPTIONS_INPUT,
};
const WHERE_ATT = {
description:
'These are the conditions that the objects need to match in order to be found',
@@ -1034,6 +1050,7 @@ const load = parseGraphQLSchema => {
parseGraphQLSchema.addGraphQLType(GEO_POINT, true);
parseGraphQLSchema.addGraphQLType(PARSE_OBJECT, true);
parseGraphQLSchema.addGraphQLType(READ_PREFERENCE, true);
parseGraphQLSchema.addGraphQLType(READ_OPTIONS_INPUT, true);
parseGraphQLSchema.addGraphQLType(SUBQUERY_INPUT, true);
parseGraphQLSchema.addGraphQLType(SELECT_INPUT, true);
parseGraphQLSchema.addGraphQLType(SEARCH_INPUT, true);
@@ -1098,6 +1115,8 @@ export {
READ_PREFERENCE_ATT,
INCLUDE_READ_PREFERENCE_ATT,
SUBQUERY_READ_PREFERENCE_ATT,
READ_OPTIONS_INPUT,
READ_OPTIONS_ATT,
WHERE_ATT,
SKIP_ATT,
LIMIT_ATT,

View File

@@ -14,7 +14,8 @@ const getParseClassQueryConfig = function(
};
const getQuery = async (className, _source, args, context, queryInfo) => {
const { id, readPreference, includeReadPreference } = args;
const { id, options } = args;
const { readPreference, includeReadPreference } = options || {};
const { config, auth, info } = context;
const selectedFields = getFieldNames(queryInfo);
@@ -58,8 +59,7 @@ const load = function(
description: `The ${getGraphQLQueryName} query can be used to get an object of the ${graphQLClassName} class by its id.`,
args: {
id: defaultGraphQLTypes.OBJECT_ID_ATT,
readPreference: defaultGraphQLTypes.READ_PREFERENCE_ATT,
includeReadPreference: defaultGraphQLTypes.INCLUDE_READ_PREFERENCE_ATT,
options: defaultGraphQLTypes.READ_OPTIONS_ATT,
},
type: new GraphQLNonNull(
classGraphQLOutputType || defaultGraphQLTypes.OBJECT
@@ -86,15 +86,12 @@ const load = function(
),
async resolve(_source, args, context, queryInfo) {
try {
const { where, order, skip, limit, options } = args;
const {
where,
order,
skip,
limit,
readPreference,
includeReadPreference,
subqueryReadPreference,
} = args;
} = options || {};
const { config, auth, info } = context;
const selectedFields = getFieldNames(queryInfo);

View File

@@ -366,9 +366,7 @@ const load = (
},
skip: defaultGraphQLTypes.SKIP_ATT,
limit: defaultGraphQLTypes.LIMIT_ATT,
readPreference: defaultGraphQLTypes.READ_PREFERENCE_ATT,
includeReadPreference: defaultGraphQLTypes.INCLUDE_READ_PREFERENCE_ATT,
subqueryReadPreference: defaultGraphQLTypes.SUBQUERY_READ_PREFERENCE_ATT,
options: defaultGraphQLTypes.READ_OPTIONS_ATT,
};
const classGraphQLOutputTypeName = `${graphQLClassName}`;
@@ -395,15 +393,12 @@ const load = (
type,
async resolve(source, args, context, queryInfo) {
try {
const { where, order, skip, limit, options } = args;
const {
where,
order,
skip,
limit,
readPreference,
includeReadPreference,
subqueryReadPreference,
} = args;
} = options || {};
const { config, auth, info } = context;
const selectedFields = getFieldNames(queryInfo);