Page tree
Skip to end of metadata
Go to start of metadata

If you need to retrieve two spaces, for example, then it won't work for both to be returned with the name "space". This is where GraphQL allows you to define an alilas that the object should be returned as. This causes two challenges, firstly for creating the query, secondly for parsing the response.

The Alilased ObjectDataSenderBuilder

There are only two differences in the ObjectDataSenderBuilders for building what fields or child objects the query should retrieve.

  1. For a normal query, the setObjectName() method uses an enum, e.g. Space.ONE_SPACE_QUERY_OBJECT_NAME which maps to "space". For aliased queries, the setObjectName() method takes the alias name you wish to use for the return object, e.g. "space1".
  2. The API needs some way to know what class to cast the return object to. This is done with a setReturnType() method of the ObjectDataSenderBuilder. To use this, there is a new enum - WWQueryResponseObjectTypes - which allows the API to know what to cast the alias to in the query and what Java class to convert the return object to.

The Multiple Query

Normal queries based on the BaseGraphQLQuery object can only take a single ObjectDataSenderBuilder, although that ObjectDataSenderBuilder may take other ObjectDataSenderBuilders as children. Aliased queries need to take more than one ObjectDataSenderBuilder at the top level.This is done with the BaseGraphQLMultiQuery. Instead of passing a single ObjectDataSenderBuilder into the constructor, you can pass either a single ObjectDataSenderBuilder to the constructor or a List of ObjectDataSenderBuilders. There are also methods for adding and removing ObjectDataSenderBuilders.

Parsing the Response

When aliases are used, the DataContainer cannot auto-convert using Gson. Instead DataContainer.getAliasedChildren() returns a Map of any aliases. The returnType property o the ObjectDataSenderBuilder is used to know what class to convert the response to.

Examples

getTwoSpaces
ObjectDataSenderBuilder query = new ObjectDataSenderBuilder();
query.setReturnType(WWQueryResponseObjectTypes.SPACE);
query.setObjectName("space1");
query.addAttribute(SpaceFields.ID, spaceId);
query.addField(SpaceFields.TITLE);
query.addField(SpaceFields.DESCRIPTION);
query.addField(SpaceFields.ID);
query.addField(SpaceFields.CREATED);
query.addField(SpaceFields.UPDATED);
BaseGraphQLMultiQuery twoSpaceQuery = new BaseGraphQLMultiQuery("getTwoSpaces", query);
ObjectDataSenderBuilder query2 = new ObjectDataSenderBuilder();
query2.setObjectName("space2");
query2.setReturnType(WWQueryResponseObjectTypes.SPACE);
query2.addAttribute(SpaceFields.ID, space2Id);
query2.addField(SpaceFields.TITLE);
query2.addField(SpaceFields.DESCRIPTION);
query2.addField(SpaceFields.ID);
query2.addField(SpaceFields.CREATED);
query2.addField(SpaceFields.UPDATED);
twoSpaceQuery.addQueryObject(query2);
ep.setRequest(new GraphQLRequest(twoSpaceQuery));
ep.executeRequest();
        
DataContainer data = ep.getResultContainer().getData();
assert (null != data);
SpaceWrapper space1 = (SpaceWrapper) data.getAliasedChildren().get("space1");
assert(null != space1);
assert (spaceName.equals(space1.getTitle()));
SpaceWrapper space2 = (SpaceWrapper) data.getAliasedChildren().get("space2");
assert(null != space2);
assert (space2Name.equals(space2.getTitle()));
getTwoSpacesFromClient
ObjectDataSenderBuilder query = new ObjectDataSenderBuilder();
query.setReturnType(WWQueryResponseObjectTypes.SPACE);
query.setObjectName("space1");
query.addAttribute(SpaceFields.ID, spaceId);
query.addField(SpaceFields.TITLE);
query.addField(SpaceFields.DESCRIPTION);
query.addField(SpaceFields.ID);
query.addField(SpaceFields.CREATED);
query.addField(SpaceFields.UPDATED);
BaseGraphQLMultiQuery twoSpaceQuery = new BaseGraphQLMultiQuery("getTwoSpaces", query);
ObjectDataSenderBuilder query2 = new ObjectDataSenderBuilder();
query2.setObjectName("space2");
query2.setReturnType(WWQueryResponseObjectTypes.SPACE);
query2.addAttribute(SpaceFields.ID, space2Id);
query2.addField(SpaceFields.TITLE);
query2.addField(SpaceFields.DESCRIPTION);
query2.addField(SpaceFields.ID);
query2.addField(SpaceFields.CREATED);
query2.addField(SpaceFields.UPDATED);
twoSpaceQuery.addQueryObject(query2);
GraphResultContainer resultContainer = client.getCustomQuery(twoSpaceQuery);
        
DataContainer data = resultContainer.getData();
assert (null != data);
SpaceWrapper space1 = (SpaceWrapper) data.getAliasedChildren().get("space1");
assert(null != space1);
assert (spaceName.equals(space1.getTitle()));
SpaceWrapper space2 = (SpaceWrapper) data.getAliasedChildren().get("space2");
assert(null != space2);
assert (space2Name.equals(space2.getTitle()));

22 Comments

  1. Anonymous

    An alias is basically any other call associated with you. It can be for a prison reason including a maiden name if a girl receives married, or a felony name change. It is able to additionally be if someone offers a fake call to police, or if their name is spelled incorrect on an professional report. instyle jackets

  2. Anonymous

    The measure of information created by these units requires the utilization of expert apparatuses and strategies for dynamic and examination. We should discover why it's imperative to learn insights and python to be an information researcher. Peruse on to discover more.  home cleaning services near me

  3. Anonymous

    Regardless of the loss of human life, the life of organizations is likewise influenced adversely. However, the vast majority of the organizations have executed the furloughing technique during the COVID-19 in various nations. This essentially implies other than of giving lay-offs the laborers you give them unpaid leaves. By implication, you trust that the circumstance will show signs of improvement and the economy to return to its position. That is the reason these laborers are kept on their unique payrolls with the goal that they can proceed with their work from where it was totally stopped. offshore company formation

  4. Anonymous

    In any case, the all the more disturbing truth to consider is that practically 60% of such independent ventures as a rule flop inside their initial two years. In fact, considering a great many organizations being worked in the UK, effectively, it isn't right to accept that making progress in Britain is almost unthinkable. ISO 9001 Dubai

  5. Anonymous

    The purchaser advertise in the UK is fixated on the web and PCs. From online life to cell phones, one just can't get enough. This demonstrates the UK showcase holds an enormous interest for every single advanced assistance. ISO 14001 Jeddah

  6. Anonymous

    With that, it is additionally critical to consider that the purchaser showcase is exceptionally serious. Along these lines, turning out to be right away fruitful can be much more testing than you might suspect. Consequently, numerous upstarts, looking for organization arrangement in the UK, presently branch out to computerized experts for help. ISO 45001 Hofuf

  7. Anonymous

    Since you comprehend what your feelings of trepidation are it's a great opportunity to design out your business and evacuate those apprehensions as deterrents. Doing things like statistical surveying, recording your objectives and destinations, constructing a serious item or administration. Hire chiller van in uae

  8. Anonymous

    As of now, there isn't any greater necessity to compose and send archives or letters through email since email (Mail ) can perform it all the more cheaply in a fabulous manner. A wide range of letters business records and archives got and can be conveyed through the web to speed business forms up. Most of the organizations are utilizing the most recent industry applications arrangements, for example, web based mechanized upkeep the executives programs which may help office administrators and professionals to discover essential business data and information quick to make support tasks increasingly productive. Via looking in Google, an organization may pick up subtleties and data about business subjects from the web. du channel list

  9. Anonymous

    Presently you can benefit of the best Du web membership on a yearly and month to month premise. Since Du Internet offers the best and energizing promotions for the customers. At truly astonishing costs you can learn further about how to do Du Internet Activation by visiting the landing page.  du moving house

  10. Anonymous

    Since the term itself indicates net promoting is publicizing over the web and the vast majority of us think about the expansive arrive at net has. You can be anyplace observed by anyone all through your promotions regardless of different components alongside the zone, in view of your battle settings. du net offers

  11. Anonymous

    The essential motivation to Begin an Internet showcasing exertion is to build the item cognizance among the watchers. While surfing through the net individuals might be considering what you're giving and may experience your image.  du internet offers

  12. Anonymous

    Reality with regards to web based promoting is that you're ready to screen each gauge as you're as of now conveying a web publicizing and showcasing exertion out from a customer's excursion and furthermore to profit. Examination is an apparatus that licenses you to measure each part of your exertion. While then again, Online Assignment Help you can quantify your ROI in the showcasing and publicizing effort that is traditional that however footfall and readership.

  13. Anonymous

    Samish Leather provides you the best quality of Faux Leather Jacket With Fur For Men, you can also Buy Tv Series Outfits from our store. we have our online store, you can visit our website.

    https://www.samishleather.com/product/faux-leather-jacket-with-fur-for-men/

  14. Anonymous

    Vid Wonders offers you the best Video Production Company Usa, we guarntees best result, as our team is professional and result oriented, we are the best Video Company. We are the worth considering for buisness.

    https://www.vidwonders.com/

  15. Anonymous

    Aone assignment offers writing services for students who asks Can Someone Write My Research Paper, assignments, thesis, dissertations, essays, and coursework and research assignments at different academic levels from school till university.

    http://www.aoneassignment.com/write-college-essay-for-less-money

  16. Anonymous

    We are giving you the opportunity to hiring someone to write college essay and that can write essays on every topic perfectly.

    https://www.hireessaywriter.com/

  17. Anonymous

    Morgan chemicals are advanced tubular glass vials suppliers for injection medicine, biological medical analysis and lab use products. You must check them out if you are concerned about it.

  18. Anonymous

    Are you looking for ac repair? So you can visit the site for more information they are providing really good services

  19. Anonymous

    Do you want to sale or buy your house? then what are you waiting for contact our estate agents in karachi.

  20. Anonymous

    Your search to Pay Someone To Do My Essay has come to an end with our academic writing company. Feel free to contact us at your convenience.

    https://www.hireessaywriter.com/pay-someone-to-do-essay Your search to Pay Someone To Do My Essay has come to an end with our academic writing company. Feel free to contact us at your convenience.
  21. Anonymous

    On the off chance that you have to recover two spaces, for instance, at that point it won't work for both to be gotten back with the name "space".  Math Assignment

  22. Anonymous

    Typical questions dependent on the BaseGraphQLQuery article can just take a solitary ObjectDataSenderBuilder, despite the fact that that ObjectDataSenderBuilder may accept different ObjectDataSenderBuilders as youngsters.   Best law assignment writers in UK

Write a comment…