Skip to content

Instantly share code, notes, and snippets.

View post.md

ES2018 (ES9)

ECMAScript 2018 was released in June 2018, adds fewer features than major editions (ES2016, ES2017) used to. These new changes are Asynchronous Iteration, Rest/Spread Properties, new features to Regular Expressions and a revision to template literals.

Asynchronous Iteration

With synchronous iteratinos, we are able to iterate data from a synchronous source, but not when data is from an asynchronous source, for example https fetch.

We will recap synchronous iteration and then asynchronous iteration.

@xoor-io
xoor-io / server.js
Created Jun 12, 2018
graphql-final-server
View server.js
// HTTP SERVER
import express from 'express';
import cors from 'cors';
// GraphQL - Apollo
import apollo from './graphql';
// Config
import config from './config';
@xoor-io
xoor-io / usgin-config.js
Created Jun 12, 2018
graphql-using-config
View usgin-config.js
function listen() {
const port = app.get('port') || config.port;
app.listen(port, () => {
console.log(`The server is running and listening at http://localhost:${port}`);
});
}
app.use(cors({
origin: config.corsDomain, // Be sure to switch to your production domain
optionsSuccessStatus: 200
@xoor-io
xoor-io / schema-index.js
Created Jun 12, 2018
graphql-schema-index
View schema-index.js
import { types, typeResolvers } from './_type';
import { queryTypes, queryResolvers } from './_query';
import inputTypes from './_input';
import { mutationTypes, mutationResolvers } from './_mutation';
export default {
types: () => [types, queryTypes, inputTypes, mutationTypes],
resolvers: Object.assign(queryResolvers, mutationResolvers, typeResolvers),
};
@xoor-io
xoor-io / _query.js
Created Jun 12, 2018
graphql-query
View _query.js
const Query = `
extend type Query {
books: [Book]
}
`;
export const queryTypes = () => [Query];
export const queryResolvers = {
Query: {
@xoor-io
xoor-io / _mutation.js
Created Jun 12, 2018
graphql-mutation
View _mutation.js
const Mutation = '';
// `
// extend type Mutation {
// }
// `;
export const mutationTypes = () => [Mutation];
export const mutationResolvers = {
View _type.js
const Book = `
type Book {
title: String!
author: String!
}
`;
export const types = () => [Book];
export const typeResolvers = {
@xoor-io
xoor-io / _input.js
Created Jun 12, 2018
graphql-input
View _input.js
const Input = '';
export default () => [Input];
@xoor-io
xoor-io / index.js
Created Jun 12, 2018
graphql-schema-index
View index.js
import fs from 'fs';
import path from 'path';
import { makeExecutableSchema } from 'graphql-tools';
import { merge } from 'lodash';
const Query = `
type Query {
status: String
}
`;
@xoor-io
xoor-io / index.js
Created Jun 11, 2018
graphql-middleware
View index.js
import bodyParser from 'body-parser';
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
import config from '../config';
import schema from './schema';
export default (app) => {
if (config.env === 'development') {
app.use('/api/graphiql', graphiqlExpress({ endpointURL: '/api' }));
}