Skip to content

Instantly share code, notes, and snippets.

View smpnjn's full-sized avatar
🥶

Johnny smpnjn

🥶
View GitHub Profile
<alpha-paragraph></alpha-paragraph>
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);
let schema = buildSchema(`
type Query {
title: [String]
articleAge: [Int]
}
`);
// 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
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',
let schema = buildSchema(`
type Query {
title(firstName: String, lastName: String): String
// ...
}
`);
let root = {
title: ({firstName, lastName}) => { return firstName + ' ' + lastName }
// ...
};
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
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;
// 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.