StringComparison not working while querying in CosmosDB - linq

Getting below error while querying the cosmosdb using stringcomparison
{
"errorCode": "DocumentQueryException",
"errorMessage": "Query expression is invalid, expression return type System.Int32 is unsupported. Query must evaluate to IEnumerable."
}
My code is something like below:
await repo.WhereAsync(something => something.Name.Equals("something", StringComparison.OrdinalIgnoreCase));
and whereasync implementation is something like below:
public async Task<IQueryable<T>> WhereAsync(Expression<Func<T, bool>> predicate, FeedOptions feedOptions = null)
{
return _client.CreateDocumentQuery<T>((await _collection).DocumentsLink, feedOptions)
.Where(predicate);
}

Related

Wrong type return in Resolver does not trigger error

I am building a sever with Graphql. I define a single query which should return a User type. However, in my resolver I am actually returning a string type: "Hello!".
The query executes in the playground without any problem.
My question: the return statement of the resolver expects a User type, instead returns a string. Why is it not failing?
TypeDef
type User {
id: String
email: String
name: String
}
type Query {
printUser: User
}
Resolver
const resolvers = {
Query: {
printUser: async (parent, args, context, info) => {
return 'Hello!';
}
}

Why graphql-js executor stops resolving child fields that have their own resolvers when the parent resolver return null/undefined?

While writing a lib for GraphQL in JavaScript I stumbled upon a curious behavior. I managed to isolate it in a very simple example. Let's take this server snippet:
const { ApolloServer, gql } = require("apollo-server")
const typeDefs = gql`
type Book {
resolveItSelf: String
}
type Query {
book: Book
}
`
const resolvers = {
Query: {
book: () => {
return null // same behavior with undefined here
}
},
Book: {
resolveItSelf: () => "resolveItSelf"
}
}
const server = new ApolloServer({ typeDefs, resolvers })
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`)
})
If we query this server with the following query:
{
book {
resolveItSelf
}
}
We get this result:
{
"data": {
"book": null
}
}
So, I was expecting the graphql executor to try to resolve the "resolveItSelf" field (which have its own resolver) even if the book resolver returned null.
A way to get the behavior I expect is to change the book's resolver a little bit:
const resolvers = {
Query: {
book: () => {
return {} // empty object instead of null/undefined
}
},
Book: {
resolveItSelf: () => "resolveItSelf"
}
}
Then we get this result:
{
"data": {
"book": {
"resolveItSelf": "resolveItSelf"
}
}
}
The field is resolved even if the parent is empty !
So my question is why the graphql-js executor stop trying to resolve fields if the parent's resolver return null/undefined, even though requested fields can be resolved on their own ? (Is there a section in the draft that cover this ?)
In GraphQL, null represents a lack of a value. If a field resolves to null, it doesn't make sense for its "child" field resolvers' to be called since they wouldn't be returned in the response anyway.
From the Value Completion section of the spec (emphasis mine):
If the fieldType is a Non‐Null type:
a. Let innerType be the inner type of fieldType.
b. Let completedResult be the result of calling CompleteValue(innerType, fields, result, variableValues).
c. If completedResult is null, throw a field error.
d. Return completedResult.
If result is null (or another internal value similar to null such as undefined or NaN), return null.
If fieldType is a List type:
a. If result is not a collection of values, throw a field error.
b. Let innerType be the inner type of fieldType.
c. Return a list where each list item is the result of calling CompleteValue(innerType, fields, resultItem, variableValues), where resultItem is each item in result.
If fieldType is a Scalar or Enum type:
a. Return the result of “coercing” result, ensuring it is a legal value of fieldType, otherwise null.
If fieldType is an Object, Interface, or Union type:
a. If fieldType is an Object type.
i. Let objectType be fieldType.
b. Otherwise if fieldType is an Interface or Union type.
i. Let objectType be ResolveAbstractType(fieldType, result).
c. Let subSelectionSet be the result of calling MergeSelectionSets(fields).
d. Return the result of evaluating ExecuteSelectionSet(subSelectionSet, objectType, result, variableValues) normally (allowing for parallelization).
In other words, even if a field's type is an Object (and therefore has a selection set of fields that may also be resolved), if it resolves to null, no further execution happens along that path.

Criteria Builder query LIKE in json field

I am trying to build a query with Criteria Builder(LIKE), to look for a string in JSONARRAY field like this:
[
{
"family_class": "Electric",
"family_name": "lightBulb"
},
{
"family_class": "Others",
"family_name": "Oil"
}
]
one option would be to look for the family_name attribute, or maybe check if it contains the string there.
if (residues != null && residues.length > 0) {
List<Predicate> predicates = new ArrayList<Predicate>();
for (String residue : residues) {
predicates.add(cb.like(root.get("jsonColumn"), residue.toLowerCase()));
}
cr.select(root).where(predicates.toArray(new Predicate[] {}));
Query<SyncCollectionPoints> q = sess.createQuery(cr);
List<SyncCollectionPoints> result= q.getResultList();
This is the error i get:
Unrecognized token 'oil': was expecting ('true', 'false' or 'null')
All i want is to return the lines that have that string in the jsonColumn field.
I got it to work like this:
#Formula(value = "lower(jsonColumn::text)")
private String residuesToSearch;
just a simple cast did the trick

GraphQL Type Error for Union Type when trying to run a query ([Error: Unknown type ...])

I have set up a graphql schema where one of the fields ('items') is a list of objects which are a Union Type i.e. the list items can be one of two object types (in this case they are called 'packageOfferItem' and 'tileItem').
var searchResultItemType = new graphql.GraphQLUnionType({
name: 'SearchResultItems',
types: [ packageOfferItem, tileItem ],
resolveType: function (value) {
if (value.type === 'packageOffer') {
return packageOfferItem;
} else if (value.type === 'tile') {
return tileItem;
} else {
return null;
}
}
});
var searchResultItemsType = new graphql.GraphQLList(searchResultItemType);
The items field is then of type searchResultItemsType.
In my tests I have a query which requests data from items filed using the notation:
{
items {
...on packageOfferItem {
id
}
}
}
In my test I get an error [Error: Unknown type "packageOfferItem".] message: 'Unknown type "packageOfferItem".' } ]
Where is this error coming from?? packageOfferItem is a graphql NamedType so I don't understand why there is an error in the query response.
Introspection of the schema does not throw any errors so the schema itself is syntactically valid.

MongoDB and Guid in Linq Where clause

I store an object in mongodb which contains a Guid. Mongodb converts the Guid to a binary value
{
"_id" : ObjectId("52cf4a467b302a4797db23e8"),
"name" : "test",
"guid" : new BinData(3, "qZ8PQdmDv0+K500wnj6skA=="),
}
I get an empty result set when I use the Guid in a Linq expression and the count is always 0.
var queryable = _database.GetCollection<MyObject>("myname").AsQueryable();
var guid = new Guid("410f9fa9-83d9-4fbf-8ae7-4d309e3eac90");
var count = queryable.Where(x => x.Guid == guid).Count();
The reason is that Linq generates the following request
count: "member_variables", query: { panelid: "410f9fa9-83d9-4fbf-8ae7-4d309e3eac90" }
but the request should be
count: "member_variables", query: { panelid: new BinData(3, "qZ8PQdmDv0+K500wnj6skA==") }
I tried various Linq expressions, but none worked.
queryable.Where(x => x.Guid.ToString() == guid.ToString())
throws the exception: "Unable to determine the serialization information for the expression: x.Guid.ToString()."
queryable.Where(x => x.Guid == new BsonBinaryData(guid));
throws the exception: "Unsupported where clause: ((BsonBinaryData)x.Guid == UuidLegacy:0x24f7ceb84f06d143b6426e8f01cb7825)."
How can I request the documents?
Note: I need to use IQuerable and can't use Mongodb queries.

Resources