How to validate data against a GraqhQL type - graphql

Having a GraphQL schema and some JSON object, is there a way to check if the object is a valid type in the schema. The only thing that I've found so far is isValidJSValue which only expects GraphQLInputType.

Related

Do I need an ID! for all types in the schema in GraphQL?

Do all types need a non-null ID? I am creating a schema and can't think of a type that wouldn't need an ID and yet most tutorials I see do not include ID.

Mongo ObjectId backward conversion from JSON to POJO

in my database I have user with ObjectId("5f78cd195a52a201fb117175").
Then I send it by Spring REST Controller to Angular Frontend and there my object id looks like this:
{date: 1601752345000, timestamp: 1601752345}
Afterwards in frontend I create product object, which contains field userId whose value is set to {date: 1601752345000, timestamp: 1601752345} . That object is sent to backend and later on is saved in db. The problem is that when it is converted by Jackson in Rest controller the userId field has value ObjectId("5f78cd19065ece5ade441e7a").
So from user with ObjectId("5f78cd195a52a201fb117175") I receive ObjectId("5f78cd19065ece5ade441e7a")
I dont have user with this second ObjectId so the field with userId contains no realtion to real user.
DO you know why it happens and how to deal with it ?
Jackson treats all objects like POJO types. By default, serialises all getter-s. Let's assume, that ObjectId instance in Java is represented by org.bson.types.ObjectId which has two getter-s:
getDate in your case date field in JSON
getTimestamp in your case timestamp field in JSON
These two fields will be serialised to JSON payload. Deserialisation process needs constructor and setters. I guess, in this case constructor ObjectId​(int timestamp, int counter) will be chosen (but I am not sure). You can try to create new instance of ObjectId using this constructor with values from your JSON payload.
When you use Jackson to serialise/deserialise types from 3-rd party libraries you can expect that there is a module implemented for this. Take a look on MongoJack:
Since MongoDB uses BSON, a binary form of JSON, to store its
documents, a JSON mapper is a perfect mechanism for mapping Java
objects to MongoDB documents. And the best Java JSON mapper is
Jackson. ...
You need to register this module and serialisation/deserialisation processes should work as expected.
See also:
How do you extract a timestamp from a MongoDB ObjectId in Spring Data MongoDB?
Binary JSON with bson4jackson

Is it possible to overwrite scalar types in GraphQL?

I want an ID scalar to serialize data not as a string but rather as a Mongo Object id. The default behaviour is serializing data as a string. I don't want to create a custom scalar with another name as it may create some difficulties down the road.
The ID type is required to serialize as a string, but absolutely nothing is specified about its format and it's intended to be opaque. You could use a Mongo object ID hex string as a GraphQL ID and (at a GraphQL level) there wouldn't be any problems with this.

Key has no data from subclass of PFUser with reference pointer field

I need to update the current user and refetch every time the App launches so that I can grasp the most updated version of user object instead of using the one cached on the disk.
User.current()?.fetchInBackground(block: { (user, error) in
//simply using a fetchInBackground won't fetch the entire reference field store in
// the user collection. In the case of using PFQuery, we could simply include the key for
// reference field.
})
Do I have to do extra fetches for all those reference field and then update the current user's filed correspondingly?
Fetch only returns the data that is stored in your database. For a pointer, that is just a basic JSON object specifying it's a pointer, the class name, and the objectId of that object. In order to return this data, you'll instead want to use a Parse Query and include the field that you want. Include works with dot notation, so you could do something like objectAQuery.include("objectB.objectC") which will include all of the data of objectC stored as a pointer on objectB. That will not include all of objectB's data, if I'm not mistaken, though I can't say with certainty.
Finally, use query.get() to get an object with a specific objectId. This will throw an error if the object does not exist, though, so make sure you handle that appropriately. You could also use query equalTo on the objectId then call query.first(), but get would be more recommended.

mapping xml to object via linq

I'm trying to run linq on xml and map to my object type, but some of the fields in the xml don't exist for some records. For example a phone number field exists most of the time for each customer in the xml file, but sometimes that tag won't exist at all. How can I check for the existence or not while mapping the data to my object via linq?

Resources