How to consume GraphQl APIs in React App in 4 steps

Note: if you don’t have running React app in your local you can create new one using `create react app`
$npx create-recat-app app-name

1 – The following packages needs to be installed

  • apollo-boost: Package containing everything you need to set up Apollo Client
  • react-apollo: View layer integration for React
  • graphql-tag: Necessary for parsing your GraphQL queries
  • graphql: Also parses your GraphQL queries
$ npm install apollo-boost react-apollo graphql-tag graphql

2 – Creating An Instance Of ApolloClient

In order to be able to access a GraphQL service from our React application we need to create an instance of ApolloClient first. This is done in App.js by adding the following code:

Note : using publicly available graphql endpoint for employee info

const client = new ApolloClient({
      uri: "https://api.graph.cool/simple/v1/ciyz901en4j590185wkmexyex"
    });

3 – Connecting ApolloClient To Your React App

Having established a connection to the GraphQL endpoint by using ApolloClient we now need to connect the instance of ApolloClient to the React app. To do so, please make sure to add the following lines of code in App.js:


<ApolloProvider client={client}>
<div>
Employee Info Apollo app
</div>
</ApolloProvider>

 

4 – Using Query Component To Request Data

To retrieve data from the GraphQL endpoint this component makes use of another component from the React Apollo library: Query. The Query component makes it extremely easy to embed the GraphQL query directly in the JSX code of the component. Furthermore the Query component contains a callback method which is invoked once the GraphQL query is executed.

Query example :

<Query
    query={gql`
      {
        allCourses {
          id
          title
          author
          description
          topic
          url
        }
      }
    `}
  >

GIT HUB – https://github.com/Sandeep821/react-graphql

DEMO : https://codesandbox.io/s/100oq6m98q

How to convert Alloy Tabs into Liferay 6.2 advance web content using velocity template

Visit Alloy UI Tab page to understand the functionality about AUI tab plugin – http://alloyui.com/examples/tabview/

STEP1: Create Web Content

In DockBar click on Admin > Content – in left nav click on ‘Web content’
Click on Add > Basic Web content

STEP 2: Add/Create structure

Create structure add fields to get tabs input.
Add filed
Tab ID – as textbox,
Tab Name – textbox
Tab Content – HtmlTextbox
Save the structure

Structure Code: https://github.com/Sandeep821/Alloy-Tab-as-a-Advance-Web-Content-Display-Liferay-6.2

——————————————————–Click here for more————————————————-
(more…)

Simple JQuery Weather Widget

This code snippet app is created by using jQuery, openweathermap.org Services. The interface is simple, and it can be easily adjusted to fit the needs and color palette of a particular project.

The weather code displays the temperature in both Celsius and Fahrenheit, User can easily change the city by passing parameter in weather function.

This code is good for learning purpose, using this user can easily make custom reusable jquery plugin and add extra feature and information.

Weather detail block could be open in Popup on click of smaller weather ticker.

How to use:

Make sure that you include the latest jQuery library in HTML and given CSS and script.

Code http://codepen.io/sandeep821/pen/RRPrpx

GitHub – https://github.com/Sandeep821/Simple-JQuery-Weather-Widget

——————————————————–Click here for more————————————————-
(more…)