Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright The Stargate Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.stargate.graphql.schema.graphqlfirst.fetchers.deployed;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.data.UdtValue;
import com.datastax.oss.driver.shaded.guava.common.collect.Maps;
import com.datastax.oss.driver.shaded.guava.common.collect.Sets;
import graphql.Scalars;
import graphql.language.ListType;
import graphql.language.Type;
import graphql.schema.GraphQLScalarType;
import io.stargate.auth.SourceAPI;
import io.stargate.auth.TypedKeyValue;
import io.stargate.auth.UnauthorizedException;
import io.stargate.db.Parameters;
import io.stargate.db.datastore.ResultSet;
import io.stargate.db.datastore.Row;
import io.stargate.db.query.BoundSelect;
import io.stargate.db.query.builder.AbstractBound;
import io.stargate.db.query.builder.BuiltCondition;
import io.stargate.db.schema.Column;
import io.stargate.db.schema.Keyspace;
import io.stargate.db.schema.UserDefinedType;
import io.stargate.graphql.schema.CassandraFetcher;
import io.stargate.graphql.schema.graphqlfirst.processor.ConditionModel;
import io.stargate.graphql.schema.graphqlfirst.processor.EntityModel;
import io.stargate.graphql.schema.graphqlfirst.processor.FieldModel;
import io.stargate.graphql.schema.graphqlfirst.processor.MappingModel;
import io.stargate.graphql.schema.graphqlfirst.util.TypeHelper;
import io.stargate.graphql.schema.scalars.CqlScalar;
import io.stargate.graphql.web.StargateGraphqlContext;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/** Base class for fetchers that handle the queries from a user's deployed schema. */
abstract class DeployedFetcher extends CassandraFetcher {
protected final MappingModel mappingModel;
public DeployedFetcher(MappingModel mappingModel) {
this.mappingModel = mappingModel;
}
protected Object toCqlValue(Object graphqlValue, Column.ColumnType cqlType, Keyspace keyspace) {
if (graphqlValue == null) {
return null;
}
if (cqlType.isParameterized()) {
if (cqlType.rawType() == Column.Type.List) {
return toCqlCollection(graphqlValue, cqlType, keyspace, ArrayList::new);
}
if (cqlType.rawType() == Column.Type.Set) {
return toCqlCollection(
graphqlValue, cqlType, keyspace, Sets::newLinkedHashSetWithExpectedSize);
}
// Map, tuple
throw new AssertionError(
String.format(
"Unsupported CQL type %s, this mapping should have failed at deployment time",
cqlType));
}
if (cqlType.isUserDefined()) {
return toCqlUdtValue(graphqlValue, cqlType, keyspace);
}
assert cqlType instanceof Column.Type;
Column.Type cqlScalarType = (Column.Type) cqlType;
// Most of the time the GraphQL runtime has already coerced the value. But if we come from a
// Federation `_entities` query, this is not possible because the representations are not
// strongly typed, and the type of each field can't be guessed. We have to do it manually:
Class> expectedClass;
GraphQLScalarType graphqlScalar;
switch (cqlScalarType) {
// Built-in GraphQL scalars:
case Int:
expectedClass = Integer.class;
graphqlScalar = Scalars.GraphQLInt;
break;
case Boolean:
expectedClass = Boolean.class;
graphqlScalar = Scalars.GraphQLBoolean;
break;
case Double:
expectedClass = Double.class;
graphqlScalar = Scalars.GraphQLFloat;
break;
case Text:
expectedClass = String.class;
graphqlScalar = Scalars.GraphQLString;
break;
default:
// Our custom CQL scalars:
CqlScalar cqlScalar =
CqlScalar.fromCqlType(cqlScalarType)
.orElseThrow(() -> new IllegalArgumentException("Unsupported type " + cqlType));
expectedClass = cqlScalar.getCqlValueClass();
graphqlScalar = cqlScalar.getGraphqlType();
break;
}
return expectedClass.isInstance(graphqlValue)
? graphqlValue
: graphqlScalar.getCoercing().parseValue(graphqlValue);
}
private Collection