<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ IBM - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ IBM - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Wed, 26 Aug 2026 17:07:41 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/ibm/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Get a rapid start on IBM Cloud with VueJS, FeathersJS, and GraphQL ]]>
                </title>
                <description>
                    <![CDATA[ By Thomas Reinecke Are you looking for a rapid start on playing around with IBMs Cloud? What about taking this opportunity and combining it with some of the latest and greatest technologies for the Web VueJS, FeathersJS and GraphQL? Well then this is... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/a-rapid-start-on-ibm-cloud-with-vuejs-feathersjs-graphql-1-2-cd2b76606d66/</link>
                <guid isPermaLink="false">66c34322790a62b5fbf7b856</guid>
                
                    <category>
                        <![CDATA[ Cloud ]]>
                    </category>
                
                    <category>
                        <![CDATA[ IBM ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Vue.js ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 16 Feb 2018 11:39:26 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*f47Cf5dkbqfW3XdFGleQ_w.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Thomas Reinecke</p>
<p>Are you looking for a rapid start on playing around with IBMs Cloud? What about taking this opportunity and combining it with some of the latest and greatest technologies for the Web VueJS, FeathersJS and GraphQL? Well then this is a must-read for you to lift-off in less than an hour.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/w4pRjRmdxL65HzbJwT7aQoSl9q1hsK2F5Zo4" alt="Image" width="668" height="388" loading="lazy"></p>
<p><strong>What we’ll do:</strong></p>
<ul>
<li>Overview of the app</li>
<li>create a fresh git repository on GitHub</li>
<li>initialize the frontend app based on Vue CLI</li>
<li>initialize the backend app based on FeathersJS CLI</li>
<li>add GraphQL capabilities to the backend</li>
<li>test the GraphQL API and publish/subscribe</li>
<li>add dependencies to the existing frontend app</li>
<li>create a simple SPA thats calling a GraphQL backend</li>
<li>deployment to IBM’s Cloud</li>
</ul>
<h3 id="heading-overview-of-the-app">Overview of the App</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/hkO5W-QuFFqay74i6Tua3j2LPbs7ZyeKjOou" alt="Image" width="638" height="480" loading="lazy"></p>
<h3 id="heading-create-a-fresh-git-repository-on-github">Create a fresh git repository on GitHub</h3>
<p>If you don’t yet have a GitHub account, go to github.com and create it. Create yourself a new repository called “VueAndIBMsCloud” (or whatever name you want). Assuming you’re well able to use a console, use the following code to create your first project commit:</p>
<pre><code class="lang-bash">mkdir VueAndIBMsCloud
<span class="hljs-built_in">cd</span> VueAndIBMsCloud
<span class="hljs-built_in">echo</span> <span class="hljs-string">"# VueAndIBMsCloud"</span> &gt;&gt; README.md
git init
git add README.md
git commit -m <span class="hljs-string">"first commit"</span>
git remote add origin https://github.com/&lt;yourRepo&gt;/VueAndIBMsCloud.git
git push -u origin master
</code></pre>
<h3 id="heading-initialise-the-frontend-app-based-on-vue-cli">Initialise the frontend app based on Vue CLI</h3>
<p>If you need more details to install Vue CLI, work through this article and come back.</p>
<p><a target="_blank" href="https://vuejs.org/v2/guide/installation.html"><strong>Installation - Vue.js</strong></a><br><a target="_blank" href="https://vuejs.org/v2/guide/installation.html"><em>Vue.js - The Progressive JavaScript Framework</em></a><br><a target="_blank" href="https://vuejs.org/v2/guide/installation.html">vuejs.org</a></p>
<p>Use the vue-cli to initialize a Progressive Web App (PWA)-based “frontend” project:</p>
<pre><code class="lang-bash">npm install -g vue-cli
vue init pwa frontend

? Project name frontend
? Project short name: fewer than 12 characters to not be truncated on homescreens (default: same as name)
? Project description A Vue.js project
? Author thomasreinecke &lt;thomas.reinecke@de.ibm.com&gt;
? Vue build runtime
? Install vue-router? Yes
? Use ESLint to lint your code? No
? Setup unit tests with Karma + Mocha? No
? Setup e2e tests with Nightwatch? No
</code></pre>
<p>Now compile the project and run it the very first time (instead of “npm” I recommend to use “yarn”):</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> frontend
yarn
yarn dev
</code></pre>
<p>Your frontend application is running at <a target="_blank" href="http://localhost:8080">http://localhost:8080</a></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/XxEi5MzErMTo6APfzLGiZqwCvqmld8XhQA67" alt="Image" width="703" height="521" loading="lazy"></p>
<p>Congratulations, you’ve just created the frontend app based on VueJs.</p>
<h3 id="heading-initialize-backend-app-based-on-feathersjs-cli">Initialize backend app based on feathersJS CLI</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/rHH7NIYxUwbv6rxsDJx4YS9mC2v7Yrv9vCFM" alt="Image" width="800" height="271" loading="lazy"></p>
<p>Use the FeathersJS CLI to initialize the backend project. If you need more details on FeatherJS CLI, use the following link and come back:</p>
<p><a target="_blank" href="https://github.com/feathersjs/cli"><strong>feathersjs/cli</strong></a><br><a target="_blank" href="https://github.com/feathersjs/cli"><em>cli - The command line interface for scaffolding Feathers applications</em></a><br><a target="_blank" href="https://github.com/feathersjs/cli">github.com</a></p>
<pre><code class="lang-bash">npm install -g @feathersjs/cli
mkdir backend
<span class="hljs-built_in">cd</span> backend
feathers generate app

? Project name backend
? Description
? What folder should the <span class="hljs-built_in">source</span> files live <span class="hljs-keyword">in</span>? src
? Which package manager are you using (has to be installed globally)? Yarn
? What <span class="hljs-built_in">type</span> of API are you making? REST, Realtime via Socket.io

yarn start
</code></pre>
<p>Your backend application is running at <a target="_blank" href="http://localhost:3030/">http://localhost:3030/</a></p>
<h3 id="heading-add-graphql-capabilities-to-the-backend">Add GraphQL capabilities to the backend</h3>
<p>Open Visual Studio Code (or your preferred IDE) &gt; Open… &gt; point it to the f<strong>older VueAndIBMs</strong>Cloud.</p>
<p>Open backend/src/index.html and replace what’s there with the following code:</p>
<pre><code class="lang-js"><span class="hljs-comment">/* eslint-disable no-console */</span>
<span class="hljs-keyword">const</span> logger = <span class="hljs-built_in">require</span>(<span class="hljs-string">'winston'</span>);
<span class="hljs-keyword">const</span> app = <span class="hljs-built_in">require</span>(<span class="hljs-string">'./app'</span>);
<span class="hljs-keyword">const</span> port = app.get(<span class="hljs-string">'port'</span>);

<span class="hljs-keyword">const</span> createSubscriptionServer = app.get(<span class="hljs-string">'createSubscriptionServer'</span>);

<span class="hljs-comment">// create subscription server and associate it to the server</span>
<span class="hljs-keyword">const</span> server = app.listen(port, <span class="hljs-function">() =&gt;</span> createSubscriptionServer(server));

process.on(<span class="hljs-string">'unhandledRejection'</span>, <span class="hljs-function">(<span class="hljs-params">reason, p</span>) =&gt;</span>
  logger.error(<span class="hljs-string">'Unhandled Rejection at: Promise '</span>, p, reason)
);

server.on(<span class="hljs-string">'listening'</span>, <span class="hljs-function">() =&gt;</span>
  logger.info(<span class="hljs-string">'Feathers application started on http://%s:%d'</span>,  
  app.get(<span class="hljs-string">'host'</span>), port)
);
</code></pre>
<p>Into the <strong>backend/package.json</strong>, add the following additional dependencies for GraphQL:</p>
<pre><code class="lang-json"><span class="hljs-string">"express-session"</span>: <span class="hljs-string">"1.15.6"</span>,
<span class="hljs-string">"graphql"</span>: <span class="hljs-string">"0.12.3"</span>,
<span class="hljs-string">"graphql-subscriptions"</span>: <span class="hljs-string">"0.5.6"</span>,
<span class="hljs-string">"graphql-tools"</span>: <span class="hljs-string">"2.18.0"</span>,
<span class="hljs-string">"subscriptions-transport-ws"</span>: <span class="hljs-string">"0.9.5"</span>,
<span class="hljs-string">"apollo-server-express"</span>: <span class="hljs-string">"1.3.2"</span>,
</code></pre>
<p>Run “<strong>yarn”</strong> on the command line to pull the additional libraries into your backend project. Now we’re ready to create the Graphql service with some more help of the feather CLI:</p>
<pre><code class="lang-bash">feathers generate service

? What kind of service is it? A custom service
? What is the name of the service? graphql
? Which path should the service be registered on? /graphql
</code></pre>
<p>You’ll realize a new directory was created: services/graphql.</p>
<p>We’re going to create the GraphQL service a little bit differently than the featherJS service template. Go ahead and delete the <strong>graphql.hooks.js</strong> and <strong>graphql.class.js.</strong></p>
<pre><code class="lang-bash">rm services/graphql/graphql.hooks.js
rm services/graphql/graphql.class.js
</code></pre>
<p>Update <strong>services/graphql/graphql.service.js</strong> with the following code:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> { graphqlExpress, graphiqlExpress } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'apollo-server-express'</span>);
<span class="hljs-keyword">const</span> { execute, subscribe } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'graphql'</span>);
<span class="hljs-keyword">const</span> { SubscriptionServer } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'subscriptions-transport-ws'</span>);
<span class="hljs-keyword">const</span> { makeExecutableSchema } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'graphql-tools'</span>);
<span class="hljs-keyword">const</span> TypeDefinitions = <span class="hljs-built_in">require</span>(<span class="hljs-string">'./graphql.typeDefs'</span>);
<span class="hljs-keyword">const</span> Resolvers = <span class="hljs-built_in">require</span>(<span class="hljs-string">'./graphql.resolvers'</span>);

<span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> app = <span class="hljs-built_in">this</span>;
  <span class="hljs-keyword">const</span> port = app.get(<span class="hljs-string">'port'</span>);
  <span class="hljs-keyword">const</span> schema = makeExecutableSchema({
    <span class="hljs-attr">typeDefs</span>: TypeDefinitions,
    <span class="hljs-attr">resolvers</span>: Resolvers.call(app)
  });

  <span class="hljs-comment">// provide endpoint to graphql for the apollo graphql client lib</span>
  app.use(<span class="hljs-string">'/graphql'</span>, graphqlExpress(<span class="hljs-function">(<span class="hljs-params">req</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> {
      schema,
      <span class="hljs-attr">context</span>: {}
    };
  }));

  <span class="hljs-comment">// provide endpoint to graphiql : the API explorer module</span>
  app.use(<span class="hljs-string">'/graphiql'</span>, graphiqlExpress({
    <span class="hljs-attr">endpointURL</span>: <span class="hljs-string">'/graphql'</span>,
    <span class="hljs-attr">subscriptionsEndpoint</span>: <span class="hljs-string">`ws://localhost:<span class="hljs-subst">${port}</span>/subscriptions`</span>
  }));

  <span class="hljs-comment">// define the API server here</span>
  app.set(<span class="hljs-string">'createSubscriptionServer'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>
    <span class="hljs-title">createSubscriptionServer</span>(<span class="hljs-params">server</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> SubscriptionServer({
      execute, subscribe, schema,
      <span class="hljs-attr">onConnect</span>: <span class="hljs-function">() =&gt;</span> { <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Client Connected'</span>); },
      <span class="hljs-attr">onDisconnect</span>: <span class="hljs-function">() =&gt;</span> { <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Client Disconnected'</span>); }
    },
    {
      server, <span class="hljs-attr">path</span>: <span class="hljs-string">'/subscriptions'</span>,
    });
  });
};
</code></pre>
<p>Now create GraphQL typedef and resolvers: create two new files under <strong>services/graphql</strong>: <strong>graphql.typeDefs.js</strong> and <strong>graphql.resolvers.js</strong> and add the following code to it:</p>
<h4 id="heading-graphqlresolversjs">graphql.resolvers.js</h4>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> { PubSub } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'graphql-subscriptions'</span>);
<span class="hljs-keyword">const</span> pubsub = <span class="hljs-keyword">new</span> PubSub();
<span class="hljs-keyword">const</span> ITEM_ADDED = <span class="hljs-string">'ITEM_ADDED'</span>;

<span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> {
    <span class="hljs-attr">Query</span>: {
      Welcome (root, { id }, context) {
        <span class="hljs-keyword">return</span> <span class="hljs-string">'Welcome to VueAndIBMsCLoud example'</span>;
      },
      Items (root, { id }, context) {
        <span class="hljs-keyword">return</span> [
          {
            <span class="hljs-attr">id</span>: <span class="hljs-number">1</span>,
            <span class="hljs-attr">title</span>: <span class="hljs-string">'Item 1'</span>,
            <span class="hljs-attr">status</span>: <span class="hljs-string">'open'</span>,
            <span class="hljs-attr">created_at</span>: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>()
          },
          {
            <span class="hljs-attr">id</span>: <span class="hljs-number">2</span>,
            <span class="hljs-attr">title</span>: <span class="hljs-string">'Item 2'</span>,
            <span class="hljs-attr">status</span>: <span class="hljs-string">'closed'</span>,
            <span class="hljs-attr">created_at</span>: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>()
          }
        ];
      }
    },
    <span class="hljs-attr">Mutation</span>: {
      addItem(root, { id, title, status }, context) {
        <span class="hljs-keyword">const</span> item = {
          id,
          title,
          status,
          <span class="hljs-attr">created_at</span>: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>()
        };
        pubsub.publish(ITEM_ADDED, { <span class="hljs-attr">itemAdded</span>: item });
        <span class="hljs-keyword">return</span> item;
      },
    },
    <span class="hljs-attr">Subscription</span>: {
      <span class="hljs-attr">itemAdded</span>: {
        <span class="hljs-attr">subscribe</span>: <span class="hljs-function">() =&gt;</span> pubsub.asyncIterator(ITEM_ADDED),
      }
    }
  };
};
</code></pre>
<h4 id="heading-graphqltypedefsjs">graphql.typeDefs.js</h4>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> typeDefinitions = <span class="hljs-string">`
  type Item {
    id: ID!
    title: String
    status: String
    created_at: String
  }

  type Query {
    Welcome: String,
    Items: [Item]
  }

  type Mutation {
    addItem(id: ID!, title: String!, status: String): Item
  }

  type Subscription {
    itemAdded: Item
  }

  schema {
    query: Query
    mutation: Mutation
    subscription: Subscription
  }
`</span>;

<span class="hljs-built_in">module</span>.exports = typeDefinitions;
</code></pre>
<p>Almost there. Let’s add a start script to <strong>package.json</strong> into the ‘scripts’ section:</p>
<pre><code class="lang-json"><span class="hljs-string">"dev"</span>: <span class="hljs-string">"NODE_ENV=development node src/"</span>,
</code></pre>
<p>And now run ‘yarn dev’. You should see a message like:<br><em>info: Feathers application started on <a target="_blank" href="http://localhost:3030">http://localhost:3030</a></em></p>
<h3 id="heading-test-the-graphql-api-and-publishsubscribe">Test the GraphQL API and publish/subscribe</h3>
<p>Try graphiQL as API explorer module <a target="_blank" href="http://localhost:3030/graphiql">http://localhost:3030/graphiq</a> and run a first test like this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Cij0N9AVsxCBewYTxbI445VIuQHYLelT9ykO" alt="Image" width="800" height="341" loading="lazy"></p>
<p>Congratulations, you have included a GraphQL API into your project!</p>
<p>Now let’s test some more complex data fetching:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/7nPlyOR4GDe-bogMKrszWYNauZrXu8Jfyadd" alt="Image" width="800" height="351" loading="lazy"></p>
<p>And now let’s test subscription. Open graphiql on a 2nd browser window and setup subscription like this and press the “play” button:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/fq3SMdiiBnB5qc0BW7Ve7hR6dT67UbcUb5hS" alt="Image" width="800" height="262" loading="lazy"></p>
<p>Now back to the first graphiql browser window, enter the following mutation which allows you to add an item to Items array. Since we’ve setup publish/subscribe, we expect to push changes to the Items array to all subscribers:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/WtwyidSbX4k3jBM-Wuzc8u4AUh85GzEgf85F" alt="Image" width="550" height="199" loading="lazy"></p>
<p>Place both browser windows next to each other and press “Play” on the first window. You’ll realize that the backend server is going to push the data change into your 2nd graphiql window:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/WZdJuyvtG2hKqyr7U9rGD2sVZhGiM04ZQqzM" alt="Image" width="800" height="252" loading="lazy"></p>
<p>How cool is that? Congrats, you’ve also setup publish/subscribe based on graphiql on your project.</p>
<h3 id="heading-add-dependencies-to-the-frontend-app">Add dependencies to the frontend app</h3>
<p>Into the <strong>frontend/package.json</strong>, add the following additional dependencies to include Graphql, ApolloJS and Subscription support (via Websockets):</p>
<pre><code class="lang-json"><span class="hljs-string">"dependencies"</span>: {
  <span class="hljs-attr">"apollo-cache-inmemory"</span>: <span class="hljs-string">"1.1.5"</span>,
  <span class="hljs-attr">"apollo-client"</span>: <span class="hljs-string">"2.2.0"</span>,
  <span class="hljs-attr">"apollo-link"</span>: <span class="hljs-string">"1.0.7"</span>,
  <span class="hljs-attr">"apollo-link-http"</span>: <span class="hljs-string">"1.3.2"</span>,
  <span class="hljs-attr">"apollo-link-ws"</span>: <span class="hljs-string">"1.0.4"</span>,
  <span class="hljs-attr">"apollo-utilities"</span>: <span class="hljs-string">"1.0.4"</span>,
  <span class="hljs-attr">"graphql"</span>: <span class="hljs-string">"0.12.3"</span>,
  <span class="hljs-attr">"graphql-tag"</span>: <span class="hljs-string">"2.6.1"</span>,
  <span class="hljs-attr">"subscriptions-transport-ws"</span>: <span class="hljs-string">"0.9.5"</span>,
  <span class="hljs-attr">"vue"</span>: <span class="hljs-string">"^2.5.2"</span>,
  <span class="hljs-attr">"vue-apollo"</span>: <span class="hljs-string">"3.0.0-alpha.3"</span>,
  <span class="hljs-attr">"vue-router"</span>: <span class="hljs-string">"^3.0.1"</span>
}
</code></pre>
<p>Run “<strong>yarn”</strong> to pull the dependencies into your frontend project.</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> frontend
yarn
</code></pre>
<p>Edit <strong>frontend/main.js</strong> and replace the code with the following:</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> Vue <span class="hljs-keyword">from</span> <span class="hljs-string">'vue'</span>
<span class="hljs-keyword">import</span> App <span class="hljs-keyword">from</span> <span class="hljs-string">'./App'</span>
<span class="hljs-keyword">import</span> router <span class="hljs-keyword">from</span> <span class="hljs-string">'./router'</span>

<span class="hljs-keyword">import</span> { ApolloClient } <span class="hljs-keyword">from</span> <span class="hljs-string">'apollo-client'</span>
<span class="hljs-keyword">import</span> { HttpLink } <span class="hljs-keyword">from</span> <span class="hljs-string">'apollo-link-http'</span>
<span class="hljs-keyword">import</span> { InMemoryCache } <span class="hljs-keyword">from</span> <span class="hljs-string">'apollo-cache-inmemory'</span>
<span class="hljs-keyword">import</span> { split } <span class="hljs-keyword">from</span> <span class="hljs-string">'apollo-link'</span>
<span class="hljs-keyword">import</span> { WebSocketLink } <span class="hljs-keyword">from</span> <span class="hljs-string">'apollo-link-ws'</span>
<span class="hljs-keyword">import</span> { getMainDefinition } <span class="hljs-keyword">from</span> <span class="hljs-string">'apollo-utilities'</span>

<span class="hljs-keyword">import</span> VueApollo <span class="hljs-keyword">from</span> <span class="hljs-string">'vue-apollo'</span>

<span class="hljs-comment">// add unified ressource identifiers for Dev and Prod (IBM Cloud)</span>
<span class="hljs-keyword">const</span> uris = {
  <span class="hljs-attr">dev</span>: <span class="hljs-string">'localhost:3030'</span>,
  <span class="hljs-attr">prod</span>: <span class="hljs-string">'VueAndIBMsCloud.mybluemix.net'</span>
}

<span class="hljs-comment">// setup httpLink depending on environment</span>
<span class="hljs-keyword">const</span> httpLink = <span class="hljs-keyword">new</span> HttpLink({
  <span class="hljs-attr">uri</span>: (<span class="hljs-built_in">window</span>.location.hostname === <span class="hljs-string">'localhost'</span>) ? <span class="hljs-string">`http://<span class="hljs-subst">${uris.dev}</span>/graphql`</span> : <span class="hljs-string">`https://<span class="hljs-subst">${uris.prod}</span>/graphql`</span>
  })

<span class="hljs-comment">// setup web socket link depending on environment</span>
<span class="hljs-keyword">const</span> wsLink = <span class="hljs-keyword">new</span> WebSocketLink({
  <span class="hljs-attr">uri</span>: (<span class="hljs-built_in">window</span>.location.hostname === <span class="hljs-string">'localhost'</span>) ? <span class="hljs-string">`ws://<span class="hljs-subst">${uris.dev}</span>/subscriptions`</span> : <span class="hljs-string">`wss://<span class="hljs-subst">${uris.prod}</span>/subscriptions`</span>,
  <span class="hljs-attr">options</span>: {
    <span class="hljs-attr">reconnect</span>: <span class="hljs-literal">true</span>
  }
})

<span class="hljs-keyword">const</span> link = split(
  <span class="hljs-function">(<span class="hljs-params">{ query }</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> { kind, operation } = getMainDefinition(query)
    <span class="hljs-keyword">return</span> kind === <span class="hljs-string">'OperationDefinition'</span> &amp;&amp; operation === <span class="hljs-string">'subscription'</span>
  },
  wsLink,
  httpLink
)

<span class="hljs-comment">// define the apolloClient</span>
<span class="hljs-keyword">const</span> apolloClient = <span class="hljs-keyword">new</span> ApolloClient({
  link,
  <span class="hljs-attr">cache</span>: <span class="hljs-keyword">new</span> InMemoryCache(),
  <span class="hljs-attr">connectToDevTools</span>: <span class="hljs-literal">true</span>
})

Vue.use(VueApollo)

<span class="hljs-keyword">const</span> apolloProvider = <span class="hljs-keyword">new</span> VueApollo({
  <span class="hljs-attr">defaultClient</span>: apolloClient
})

Vue.config.productionTip = <span class="hljs-literal">false</span>

<span class="hljs-comment">/* eslint-disable no-new */</span>
<span class="hljs-keyword">new</span> Vue({
  <span class="hljs-attr">el</span>: <span class="hljs-string">'#app'</span>,
  apolloProvider,
  router,
  <span class="hljs-attr">render</span>: <span class="hljs-function"><span class="hljs-params">h</span> =&gt;</span> h(App)
})
</code></pre>
<p>This will prepare your frontend app to use ApolloClient as Library to provide GraphQL Query, Mutation and Subscription support. On the <strong>uris</strong> object, replace <strong>VueAndIBMsCloud.mybluemix.net</strong> with your productive deployment target of the backend app.</p>
<h3 id="heading-add-ui-calling-the-graphql-backend">Add UI calling the GraphQL backend</h3>
<p>In your frontend sources, open <strong>src/App.vue</strong> and replace it with the following code:</p>
<pre><code class="lang-js">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>{{ welcome }}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">v-for</span>=<span class="hljs-string">"(item) of items"</span> <span class="hljs-attr">v-bind:key</span>=<span class="hljs-string">"item.id"</span>&gt;</span>{{item.title + ' - ' + item.status}}<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">import</span> gql <span class="hljs-keyword">from</span> <span class="hljs-string">'graphql-tag'</span>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  <span class="hljs-attr">name</span>: <span class="hljs-string">'app'</span>,
  data () {
    <span class="hljs-keyword">return</span> {
      <span class="hljs-attr">welcome</span>: <span class="hljs-string">''</span>,
      <span class="hljs-attr">items</span>: []
    }
  },
  mounted () {
    <span class="hljs-built_in">this</span>.$apollo.query({
      <span class="hljs-attr">query</span>: gql<span class="hljs-string">`query {
        Welcome
        Items {
          id
          title
          status
        }
      }`</span>
    }).then(<span class="hljs-function">(<span class="hljs-params">{data}</span>) =&gt;</span> {
      <span class="hljs-built_in">this</span>.welcome = data.Welcome
      <span class="hljs-built_in">this</span>.items = data.Items
    }).catch(<span class="hljs-function">(<span class="hljs-params">error</span>) =&gt;</span> {
      <span class="hljs-built_in">console</span>.error(error)
    })
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
<span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">50px</span>;
}

<span class="hljs-selector-id">#app</span> {
  <span class="hljs-attribute">font-family</span>: <span class="hljs-string">'Avenir'</span>, Helvetica, Arial, sans-serif;
  <span class="hljs-attribute">-webkit-font-smoothing</span>: antialiased;
  <span class="hljs-attribute">-moz-osx-font-smoothing</span>: grayscale;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#2c3e50</span>;
}

<span class="hljs-selector-tag">main</span> {
  <span class="hljs-attribute">text-align</span>: center;
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">40px</span>;
}

<span class="hljs-selector-tag">header</span> {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">56px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span> <span class="hljs-number">16px</span> <span class="hljs-number">0</span> <span class="hljs-number">24px</span>;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#35495E</span>;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#ffffff</span>;
}

<span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">span</span> {
  <span class="hljs-attribute">display</span>: block;
  <span class="hljs-attribute">position</span>: relative;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">letter-spacing</span>: .<span class="hljs-number">02em</span>;
  <span class="hljs-attribute">font-weight</span>: <span class="hljs-number">400</span>;
  <span class="hljs-attribute">box-sizing</span>: border-box;
  <span class="hljs-attribute">padding-top</span>: <span class="hljs-number">16px</span>;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>Save and run <strong>yarn dev</strong> to start it. You should now see the new landing page of your frontend app (which does not yet look super exciting, but this is the first time we see data from your graphQL backend in your frontend — isn’t that cool?)</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/kJq1yDrUsyjTXkCruNi4mTFqNsuIztSUHNbF" alt="Image" width="800" height="244" loading="lazy"></p>
<p>Now since we have our e2e integration between our frontend and graphQL backend, let’s push it to IBMs cloud and run it there.</p>
<h3 id="heading-preparing-ibm-cloud-for-deployment">Preparing IBM Cloud for Deployment</h3>
<ul>
<li>setup Bluemix CLI on your desktop: <a target="_blank" href="https://console.bluemix.net/docs/cli/reference/bluemix_cli/get_started.html#getting-started">https://console.bluemix.net/docs/cli/reference/bluemix_cli/get_started.html#getting-started</a></li>
<li>login to IBM’s cloud: <strong>bx login</strong></li>
<li>set target and space context in IBMs Cloud interactively (go to <a target="_blank" href="https://console.bluemix.net/dashboard/apps/">https://console.bluemix.net/dashboard/apps/</a> to inspect your options): <strong>bx target — cf</strong></li>
</ul>
<p>You now should see this:</p>
<pre><code>API endpoint:     &lt;your endpoint&gt; (&lt;API version&gt;)
Region:           &lt;your region&gt;
User:             &lt;your username&gt;
Account:          &lt;your account&gt;
Resource group:   default
Org:              &lt;your org&gt;
Space:            &lt;your space&gt;
</code></pre><p>You have now set the deployment scope for your two apps.</p>
<h3 id="heading-deployment-of-the-backend-to-bluemix">Deployment of the Backend to Bluemix</h3>
<p>On the backend project, create a new manifest.yml file and enter the following contents into it:</p>
<pre><code class="lang-yml"><span class="hljs-attr">applications:</span>
  <span class="hljs-bullet">-</span> <span class="hljs-attr">path:</span> <span class="hljs-string">.</span>
    <span class="hljs-attr">memory:</span> <span class="hljs-string">1024M</span>
    <span class="hljs-attr">instances:</span> <span class="hljs-number">1</span>
    <span class="hljs-attr">domain:</span> <span class="hljs-string">eu-de.mybluemix.net</span>
    <span class="hljs-attr">name:</span> <span class="hljs-string">vueAndIbmsCloud-api</span>
    <span class="hljs-attr">host:</span> <span class="hljs-string">vueAndIbmsCloud-api</span>
    <span class="hljs-attr">disk_quota:</span> <span class="hljs-string">1024M</span>
</code></pre>
<p>Add the following deploy script to package.json to the “scripts” section:</p>
<pre><code class="lang-json"><span class="hljs-string">"deploy"</span>: <span class="hljs-string">"bx cf push vueAndIbmsCloud-api"</span>
</code></pre>
<p>(You have to change that app name to make it unique, e.g. append some index of your choice on manifest.yml and package.json.)</p>
<h4 id="heading-install-bluemix-cli"><strong>Install BlueMix CLI</strong></h4>
<p><a target="_blank" href="https://console.bluemix.net/docs/cli/index.html">https://console.bluemix.net/docs/cli/index.html</a><br><a target="_blank" href="https://developer.ibm.com/courses/labs/1-install-bluemix-command-line-interface-cli-dwc020/">https://developer.ibm.com/courses/labs/1-install-bluemix-command-line-interface-cli-dwc020/</a></p>
<p>Run <strong>yarn deploy</strong>, and this will deploy your backend app to the IBM Cloud.</p>
<h3 id="heading-deployment-of-the-frontend-to-bluemix">Deployment of the Frontend to Bluemix</h3>
<p>We deploy the frontend app based on an nginx server, which provides a better performance (in responsetime and throughput) than a node server.</p>
<p>Depending on what name you picked as your backend deployment target, let’s make sure it’s properly reflected in <strong>frontend/src/main.js</strong>. In the <strong>uris</strong> object, replace ‘vueandibmscloud-api.eu-de.mybluemix.net’ with the URL where your backend server is. You can inspect the URL in the Bluemix console &gt; click into your app &gt; view App URL.</p>
<p>On the frontend application root folder, create the manifest.yml and include the following contents:</p>
<pre><code class="lang-yml"><span class="hljs-attr">applications:</span>
  <span class="hljs-bullet">-</span> <span class="hljs-attr">path:</span> <span class="hljs-string">.</span>
    <span class="hljs-attr">memory:</span> <span class="hljs-string">1024M</span>
    <span class="hljs-attr">instances:</span> <span class="hljs-number">1</span>
    <span class="hljs-attr">domain:</span> <span class="hljs-string">mybluemix.net</span>
    <span class="hljs-attr">name:</span> <span class="hljs-string">vueAndIbmsCloud</span>
    <span class="hljs-attr">host:</span> <span class="hljs-string">vueAndIbmsCloud</span>
    <span class="hljs-attr">disk_quota:</span> <span class="hljs-string">1024M</span>
    <span class="hljs-attr">buildpack:</span> <span class="hljs-string">staticfile_buildpack</span>
</code></pre>
<p>Add the following deploy script to package.json to the “scripts” section:</p>
<pre><code class="lang-json"><span class="hljs-string">"deploy"</span>: <span class="hljs-string">"npm run build; cp manifest.yml dist/manifest.yml; cd dist; bx cf push vueAndIbmsCloud"</span>
</code></pre>
<p>(You have to change that app name to make it unique, e.g. append some index of your choice on manifest.yml and package.json.)</p>
<p>Run <strong>yarn deploy</strong>, and this will deploy your frontend app to the IBM Cloud.</p>
<p>Congratulations :) You can now use your frontend app on IBM’s Cloud.</p>
<p>Find the sources at GitHub: <a target="_blank" href="https://github.com/thomasreinecke/VueAndIBMsCloud">https://github.com/thomasreinecke/VueAndIBMsCloud</a></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
