This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<alpha-paragraph></alpha-paragraph> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Paragraph extends HTMLElement { | |
constructor() { | |
super() | |
this.innerHTML = '<p>Hello</p>' | |
} | |
} | |
// define adds a custom element "alpha-paragraph" using the rules defined in the "Paragraph" class | |
customElements.define('alpha-paragraph', Paragraph); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let root = { | |
title: async () => { | |
let allArticles = []; | |
// Query our mongoDB | |
let articles = await Article.find(); | |
// Return data in appropriate format | |
articles.forEach(function(item) { | |
if(typeof item.title === "string") { | |
allArticles.push(item.title); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let schema = buildSchema(` | |
type Query { | |
title: [String] | |
articleAge: [Int] | |
} | |
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import mongoose | |
import mongoose from 'mongoose'; | |
// Models | |
import { Article } from './models/article.model.js'; | |
// Connect to our mongoDB | |
const database = 'mongodb://localhost:27017/database'; | |
mongoose.connect(database, { | |
useNewUrlParser: true, | |
useUnifiedTopology: true, | |
useFindAndModify: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mongoose from 'mongoose' | |
const database = 'mongodb://localhost:27017/articles'; | |
const connection = mongoose.createConnection(database, { | |
useNewUrlParser: true, | |
useUnifiedTopology: true, | |
useFindAndModify: false | |
}); | |
const schema = new mongoose.Schema({ | |
title: 'String', | |
description: 'String', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let schema = buildSchema(` | |
type Query { | |
title(firstName: String, lastName: String): String | |
// ... | |
} | |
`); | |
let root = { | |
title: ({firstName, lastName}) => { return firstName + ' ' + lastName } | |
// ... | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from 'express'; | |
import { graphqlHTTP } from 'express-graphql'; | |
import { buildSchema } from 'graphql' | |
/* A schema is used to define how the data will look */ | |
let schema = buildSchema(` | |
type Query { | |
title: String, | |
age: Int, | |
description: String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let html = '<h2><i class="fas fa-fire-alt"></i> Recently Popular</h2><ol>'; | |
newObj.forEach(function(item) { | |
html += `<li><a href="${item.url}">${item.title}</a></li>` | |
}); | |
html += '</ol>'; | |
return html; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// newObj will contain the views, url and title for all of our pages. You may have to adjust this for your own needs. | |
let topRows = 7; // Number of items we want to return | |
let pageTitle = 'Fjolt - '; // The part off the front of the page title we want to remove, usually the domain name | |
let blogUrl = '/article/'; // The URLs we want to target. | |
let newObj = []; | |
response.rows.forEach(row => { | |
// dimensionValues[0] contains 'pagePathPlusQueryString', and dimensionsValues[1] contains 'pageTitle' | |
// We will remove and percentages from the end of URLs to clean them up. You may have to adjust this | |
// If you make use of percentages normally in your URLs. |