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

Slide4

Multi-Tenant Application

Multi-Tenant Application built with REACT (FE) and AWS lambda (API), changes ist behavior content according to a tenant

Feature: Multitenancy, Multitenancy configuration CMS, UI CMS, Dynamic theme, theme CMS, Initialization/Localization, Cloud configuration VW Portal POC Task Page 2 Initialization/Localization, Cloud configuration

Tech stack: HTML5, ES6, SASS (node-sass-chokidar), React, Redux, JEST, react-intel, bootstrap, Webpack, VS Code, NodeJS, ExpressJS, DynamoDB, Git, GitHub, Concourse CI, Docker, AWS CloudFront (S3), AWS Lambda

GIT REPO FE – https://github.com/Sandeep821/Multi-Tenant-React-App

GIT REPO BE – https://github.com/Sandeep821/Multi-Tenant-Serverless-AWS-UI-Api (Serverless API deployed on AWS)

DEMO – http://multi-tenant-app-fe.s3-website.us-east-2.amazonaws.com/

  • [for Audi: userId : audi, password: demo]
  • [Bugatti: userId : bugatti, password: demo]

Architecture:

https://github.com/Sandeep821/Multi-Tenant-React-App/blob/master/docs/MultiTenant%20App.pptx

Credit Card Validation – Angular Directive

Codepen url – http://codepen.io/sandeep821/pen/BLdVgW

Valid credit card numbers to test :

Visa : 4532069777249404 , 4916014173889326
Master : 5194775997768660, 5494872713298895
Amex : 340251740623507, 375921122764396
Discover : 6011489471829878 , 6011782582773435

Ref : https://en.wikipedia.org/wiki/Luhn_algorithm

LUHN Formula (Mod 10) for Validation of Primary Account Number

Step 1: Double the value of alternate digits of the primary account number beginning with the second digit from the right (the first right–hand digit is the check digit.)

Step 2: Add the individual digits comprising the products obtained in Step 1 to each of the unaffected digits in the original number.

Step 3: The total obtained in Step 2 must be a number ending in zero (30, 40, 50, etc.) for the account number to be validated.

Prefix, Length, and Check Digit Criteria

CARD TYPE Prefix Length Check digit algorithm
MASTERCARD 51-55 16 mod 10
VISA 4 13, 16 mod 10
AMEX 34

37
15 mod 10
Diners Club/
Carte Blanche
300-305
36
38
14 mod 10
Discover 6011 16 mod 10
enRoute 2014
2149
15 any
JCB 3 16 mod 10
JCB 2131
1800
15 mod 10

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…)

Liferay 6.2 Parent and Child theme

First create Parent Theme

  • Go to File → New → Liferay Project.
  • Fill in the Project name and Display name fields.
  • Select the Liferay Plugins SDK and Portal Runtime you’ve configured.
  • Select Theme for your Plugin type.
  • Click Next.

1-theme-create-a-theme-project

  • Select a theme parent. Your theme inherits the parent theme’s styling as a base from
    which to build your theme. In addition to the _styled theme, you can choose to inherit
    from the _unstyled theme, which contains no styling. There’s also the classic theme
    that has a smooth look and feel and works well. I have chosen “classic”
  • Select your theme’s framework. You can select the Freemarker or Velocity template
    frameworks for your theme. I have chosen “Velocity”

 

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