master 6d2344b64cd8 cached
12 files
18.7 KB
5.1k tokens
15 symbols
1 requests
Download .txt
Repository: reindexio/graphql-nodejs-newsfeed
Branch: master
Commit: 6d2344b64cd8
Files: 12
Total size: 18.7 KB

Directory structure:
gitextract_9gucwcnm/

├── .babelrc
├── .eslintrc
├── .gitignore
├── LICENSE
├── README.md
├── Schema.js
├── SqlitePlugin.js
├── config.js
├── index.js
├── package.json
├── scripts/
│   └── createdb.sql
└── server.js

================================================
FILE CONTENTS
================================================

================================================
FILE: .babelrc
================================================
{
  "stage": 1
}


================================================
FILE: .eslintrc
================================================
{
  "parser": "babel-eslint",
  "env": {
    "node": true,
    "mocha": true
  },
  "rules": {
    "brace-style": 2,
    "camelcase": 2,
    "comma-dangle": [2, "never"],
    "comma-style": 2,
    "dot-notation": 2,
    "eol-last": 2,
    "eqeqeq": 2,
    "indent": [2, 2],
    "key-spacing": 2,
    "max-len": [2, 80, 2],
    "no-array-constructor": 2,
    "no-dupe-keys": 2,
    "no-eq-null": 2,
    "no-extra-boolean-cast": 2,
    "no-extra-parens": [2, "functions"],
    "no-multi-spaces": 2,
    "no-multi-str": 2,
    "no-new-object": 2,
    "no-shadow-restricted-names": 2,
    "no-spaced-func": 2,
    "no-unused-vars": 2,
    "no-use-before-define": 0,
    "no-var": 2,
    "object-shorthand": 2,
    "one-var": [2, "never"],
    "prefer-const": 2,
    "quote-props": [2, "as-needed"],
    "quotes": [2, "single"],
    "semi-spacing": 2,
    "semi": [2, "always"],
    "space-before-blocks": 2,
    "space-before-function-paren": [2, "never"],
    "space-infix-ops": 2,
    "spaced-comment": 2,
    "strict": 0,
    "use-isnan": 2,
    "valid-jsdoc": 0
  }
}


================================================
FILE: .gitignore
================================================
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

db.sqlite3


================================================
FILE: LICENSE
================================================
The MIT License (MIT)

Copyright (c) 2015-present, Reindex Software

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


================================================
FILE: README.md
================================================
# graphql-nodejs-newsfeed
Example of graphql nodejs backend with newsfeed, built with hapi and sqlite

## Set Up Database

```
$ sqlite3 db.sqlite3 < scripts/createdb.sql
```

## Run Server

```
$ npm start
```

## Example Query

```
$ curl --data "query={ __schema { types { name } } }" localhost:8000
```


================================================
FILE: Schema.js
================================================
import {
  GraphQLSchema,
  GraphQLObjectType,
  GraphQLID,
  GraphQLString,
  GraphQLNonNull,
  GraphQLList
} from 'graphql';

const Story = new GraphQLObjectType({
  name: 'Story',
  fields: () => ({
    id: {
      type: GraphQLID
    },
    text: {
      type: GraphQLString
    },
    author: {
      type: User,
      resolve(parent, args, {rootValue: {db}}) {
        return db.get(`
          SELECT * FROM User WHERE id = $id
        `, {$id: parent.author});
      }
    }
  })
});

const User = new GraphQLObjectType({
  name: 'User',
  fields: () => ({
    id: {
      type: GraphQLID
    },
    name: {
      type: GraphQLString
    },
    stories: {
      type: new GraphQLList(Story),
      resolve(parent, args, {rootValue: {db}}) {
        return db.all(`
          SELECT * FROM Story WHERE author = $user
        `, {$user: parent.id});
      }
    }
  })
});

const Query = new GraphQLObjectType({
  name: 'Query',
  fields: () => ({
    viewer: {
      type: User,
      resolve(parent, args, {rootValue: {db, userId}}) {
        return db.get(`
          SELECT * FROM User WHERE id = $id
        `, {$id: userId});
      }
    },
    user: {
      type: User,
      args: {
        id: {
          type: new GraphQLNonNull(GraphQLID)
        }
      },
      resolve(parent, {id}, {rootValue: {db}}) {
        return db.get(`
          SELECT * FROM User WHERE id = $id
          `, {$id: id});
      }
    },
    story: {
      type: Story,
      args: {
        id: {
          type: new GraphQLNonNull(GraphQLID)
        }
      },
      resolve(parent, {id}, {rootValue: {db}}) {
        return db.get(`
          SELECT * FROM Story WHERE id = $id
          `, {$id: id});
      }
    }
  })
});

const Schema = new GraphQLSchema({
  query: Query
});
export default Schema;


================================================
FILE: SqlitePlugin.js
================================================
import sqlite3 from 'sqlite3';
import {DB_PATH} from './config';
import {promisify} from 'bluebird';

async function openConnection(request, reply) {
  try {
    request.db = new sqlite3.Database(DB_PATH);
    request.db.get = promisify(request.db.get);
    request.db.all = promisify(request.db.all);

    reply.continue();
  } catch (error) {
    reply(error);
  }
}

async function closeConnection(request) {
  if (request.db) {
    await request.db.close();
  }
}

function register(server, options, next) {
  server.ext('onRequest', openConnection);
  server.on('tail', closeConnection);
  next();
}

register.attributes = {
  name: 'SqlitePlugin'
};

const SqlitePlugin = {register};
export default SqlitePlugin;


================================================
FILE: config.js
================================================
export const DB_PATH = './db.sqlite3';
export const HOST = 'localhost';
export const PORT = '8000';


================================================
FILE: index.js
================================================
require('babel/register');
require('./server')();


================================================
FILE: package.json
================================================
{
  "name": "graphql-nodejs-newsfeed",
  "version": "1.0.0",
  "description": "Example of graphql nodejs backend with newsfeed, built with hapi and sqlite",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/freiksenet/graphql-nodejs-newsfeed.git"
  },
  "author": "Mikhail <freiksenet@gmail.com>",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/freiksenet/graphql-nodejs-newsfeed/issues"
  },
  "homepage": "https://github.com/freiksenet/graphql-nodejs-newsfeed#readme",
  "dependencies": {
    "babel": "^5.8.19",
    "bluebird": "^2.9.34",
    "graphql": "^0.4.3",
    "hapi": "^8.8.0",
    "sqlite3": "^3.0.9"
  },
  "devDependencies": {
    "babel-eslint": "^4.0.5",
    "eslint": "^0.24.1",
    "mocha": "^2.2.5"
  }
}


================================================
FILE: scripts/createdb.sql
================================================
DROP TABLE IF EXISTS Story;
DROP TABLE IF EXISTS User;

CREATE TABLE User
(
  id INTEGER PRIMARY KEY,
  name VARCHAR(255)
);

CREATE TABLE Story
(
  id INTEGER PRIMARY KEY,
  text TEXT,
  author INTEGER,
  FOREIGN KEY(author) REFERENCES User(id)
);

INSERT INTO User('name')
VALUES
('freiksenet'),
('fson'),
('Hallie'),
('Sophia'),
('Riya'),
('Kari'),
('Estrid'),
('Burwenna'),
('Emma'),
('Kaia'),
('Halldora'),
('Dorte');

INSERT INTO Story ('text', 'author')
VALUES ('One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.', 1),
('He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections.', 1),
('The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked.', 1),
('"What''s happened to me? " he thought. It wasn''t a dream. His room, a proper human room although a little too small, lay peacefully between its four familiar walls.', 1),
('A collection of textile samples lay spread out on the table - Samsa was a travelling salesman - and above it there hung a picture that he had recently cut out of an illustrated magazine and housed in a nice, gilded frame.', 2),
('It showed a lady fitted out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards the viewer.', 3),
('Gregor then turned to look out the window at the dull weather. Drops of rain could be heard hitting the pane, which made him feel quite sad.', 2),
('"How about if I sleep a little bit longer and forget all this nonsense", he thought, but that was something he was unable to do because he was used to sleeping on his right, and in his present state couldn''t get into that position.', 4),
('However hard he threw himself onto his right, he always rolled back to where he was.', 1),
('He must have tried it a hundred times, shut his eyes so that he wouldn''t have to look at the floundering legs, and only stopped when he began to feel a mild, dull pain there that he had never felt before.', 1),
('"Oh, God", he thought, "what a strenuous career it is that I''ve chosen! Travelling day in and day out.', 1),
('Doing business like this takes much more effort than doing your own business at home, and on top of that there''s the curse of travelling, worries about making train connections, bad and irregular food, contact with different people all the time so that you can never get to know anyone or become friendly with them.', 1),
('It can all go to Hell!', 2),
('" He felt a slight itch up on his belly; pushed himself slowly up on his back towards the headboard so that he could lift his head better; found where the itch was, and saw that it was covered with lots of little white spots which he didn''t know what to make of; and when he tried to feel the place with one of his legs he drew it quickly back because as soon as he touched it he was overcome by a cold shudder.', 3),
('He slid back into his former position. "Getting up early all the time", he thought, "it makes you stupid. You''ve got to get enough sleep. Other travelling salesmen live a life of luxury.', 5),
('For instance, whenever I go back to the guest house during the morning to copy out the contract, these gentlemen are always still sitting there eating their breakfasts.', 6),
('I ought to just try that with my boss; I''d get kicked out on the spot. But who knows, maybe that would be the best thing for me.', 7),
('If I didn''t have my parents to think about I''d have given in my notice a long time ago, I''d have gone up to the boss and told him just what I think, tell him everything I would, let him know just what I feel.', 10),
('He''d fall right off his desk!', 1),
('And it''s a funny sort of business to be sitting up there at your desk, talking down at your subordinates from up there, especially when you have to go right up close because the boss is hard of hearing.', 2),
('Well, there''s still some hope; once I''ve got the money together to pay off my parents'' debt to him - another five or six years I suppose - that''s definitely what I''ll do. That''s when I''ll make the big change.', 3),
('First of all though, I''ve got to get up, my train leaves at five. " And he looked over at the alarm clock, ticking on the chest of drawers. "God in Heaven! " he thought.', 5),
('It was half past six and the hands were quietly moving forwards, it was even later than half past, more like quarter to seven. Had the alarm clock not rung?', 2),
('He could see from the bed that it had been set for four o''clock as it should have been; it certainly must have rung. Yes, but was it possible to quietly sleep through that furniture-rattling noise?', 1),
('True, he had not slept peacefully, but probably all the more deeply because of that. What should he do now?', 1),
('The next train went at seven; if he were to catch that he would have to rush like mad and the collection of samples was still not packed, and he did not at all feel particularly fresh and lively.', 1),
('And even if he did catch the train he would not avoid his boss''s anger as the office assistant would have been there to see the five o''clock train go, he would have put in his report about Gregor''s not being there a long time ago.', 1),
('The office assistant was the boss''s man, spineless, and with no understanding. What about if he reported sick? But that would be extremely strained and suspicious as in fifteen years of service Gregor had never once yet been ill.', 1),
('His boss would certainly come round with the doctor from the medical insurance company, accuse his parents of having a lazy son, and accept the doctor''s recommendation not to make any claim as the doctor believed that no-one was ever ill but that many were workshy.', 2),
('And what''s more, would he have been entirely wrong in this case? Gregor did in fact, apart from excessive sleepiness after sleeping for so long, feel completely well and even felt much hungrier than usual.', 3),
('One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.', 1),
('He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment.', 1),
('His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. "What''s happened to me? " he thought. It wasn''t a dream.', 1),
('His room, a proper human room although a little too small, lay peacefully between its four familiar walls.', 1),
('A collection of textile samples lay spread out on the table - Samsa was a travelling salesman - and above it there hung a picture that he had recently cut out of an illustrated magazine and housed in a nice, gilded frame.', 5),
('It showed a lady fitted out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards the viewer. Gregor then turned to look out the window at the dull weather.', 5),
('Drops of rain could be heard hitting the pane, which made him feel quite sad.', 5),
('"How about if I sleep a little bit longer and forget all this nonsense", he thought, but that was something he was unable to do because he was used to sleeping on his right, and in his present state couldn''t get into that position.', 3),
('However hard he threw himself onto his right, he always rolled back to where he was. He must have tried it a hundred times, shut his eyes so that he wouldn''t have to look at the floundering legs, and only stopped when he began to feel a mild, dull pain there that he had never felt before.', 1),
('"Oh, God", he thought, "what a strenuous career it is that I''ve chosen! Travelling day in and day out.', 2),
('Doing business like this takes much more effort than doing your own business at home, and on top of that there''s the curse of travelling, worries about making train connections, bad and irregular food, contact with different people all the time so that you can never get to know anyone or become friendly with them. It can all go to Hell!', 3),
('" He felt a slight itch up on his belly; pushed himself slowly up on his back towards the headboard so that he could lift his head better; found where the itch was, and saw that it was covered with lots of little white spots which he didn''t know what to make of; and when he tried to feel the place with one of his legs he drew it quickly back because as soon as he touched it he was overcome by a cold shudder.', 3),
('He slid back into his former position. "Getting up early all the time", he thought, "it makes you stupid. You''ve got to get enough sleep. Other travelling salesmen live a life of luxury.', 3),
('For instance, whenever I go back to the guest house during the morning to copy out the contract, these gentlemen are always still sitting there eating their breakfasts. I ought to just try that with my boss; I''d get kicked out on the spot. But who knows, maybe that would be the best thing for me.', 6),
('If I didn''t have my parents to think about I''d have given in my notice a long time ago, I''d have gone up to the boss and told him just what I think, tell him everything I would, let him know just what I feel. He''d fall right off his desk!', 6),
('And it''s a funny sort of business to be sitting up there at your desk, talking down at your subordinates from up there, especially when you have to go right up close because the boss is hard of hearing. Well, there''s still some hope; once I''ve got the money together to pay off my parents'' debt to him - another five or six years I suppose - that''s definitely what I''ll do.', 6),
('That''s when I''ll make the big change. First of all though, I''ve got to get up, my train leaves at five. " And he looked over at the alarm clock, ticking on the chest of drawers. "God in Heaven! " he thought. It was half past six and the hands were quietly moving forwards, it was even later than half past, more like quarter to seven.', 2),
('Had the alarm clock not rung? He could see from the bed that it had been set for four o''clock as it should have been; it certainly must have rung. Yes, but was it possible to quietly sleep through that furniture-rattling noise? True, he had not slept peacefully, but probably all the more deeply because of that. What should he do now?', 1),
('The next train went at seven; if he were to catch that he would have to rush like mad and the collection of samples was still not packed, and he did not at all feel particularly fresh and lively. And even if he did catch the train he would not avoid his boss''s anger as the office assistant would have been there to see the five o''clock train go, he would have put in his report about Gregor''s not being there a long time ago.', 1),
('The office assistant was the boss''s man, spineless, and with no understanding. What about if he reported sick? But that would be extremely strained and suspicious as in fifteen years of service Gregor had never once yet been ill. His boss would certainly come round with the doctor from the medical insurance company, accuse his parents of having a lazy son, and accept the doctor''s recommendation not to make any claim as the doctor believed that ', 1);


================================================
FILE: server.js
================================================
import Hapi from 'hapi';
import {graphql} from 'graphql';
import {promisify} from 'bluebird';
import {HOST, PORT} from './config';
import SqlitePlugin from './SqlitePlugin';
import Schema from './Schema';

async function graphQLHandler(request, reply) {
  const {query, variables = {}} = request.payload;
  const result = await graphql(
    Schema,
    query,
    {
      db: request.db,
      userId: '1'
    },
    variables
  );
  return reply(result);
}

export default async function runServer() {
  try {
    const server = new Hapi.Server();

    // Make server methods promise friendly
    for (const method of ['register', 'start']) {
      server[method] = promisify(server[method], server);
    }

    server.connection({
      host: HOST,
      port: PORT
    });

    await server.register(SqlitePlugin);

    server.route({
      method: 'POST',
      path: '/',
      handler: graphQLHandler
    });

    await server.start();

    console.log('Server started at ' + server.info.uri);
  } catch(e) {
    console.log(e);
  }
}
Download .txt
gitextract_9gucwcnm/

├── .babelrc
├── .eslintrc
├── .gitignore
├── LICENSE
├── README.md
├── Schema.js
├── SqlitePlugin.js
├── config.js
├── index.js
├── package.json
├── scripts/
│   └── createdb.sql
└── server.js
Download .txt
SYMBOL INDEX (15 symbols across 5 files)

FILE: Schema.js
  method resolve (line 21) | resolve(parent, args, {rootValue: {db}}) {
  method resolve (line 41) | resolve(parent, args, {rootValue: {db}}) {
  method resolve (line 55) | resolve(parent, args, {rootValue: {db, userId}}) {
  method resolve (line 68) | resolve(parent, {id}, {rootValue: {db}}) {
  method resolve (line 81) | resolve(parent, {id}, {rootValue: {db}}) {

FILE: SqlitePlugin.js
  function openConnection (line 5) | async function openConnection(request, reply) {
  function closeConnection (line 17) | async function closeConnection(request) {
  function register (line 23) | function register(server, options, next) {

FILE: config.js
  constant DB_PATH (line 1) | const DB_PATH = './db.sqlite3';
  constant HOST (line 2) | const HOST = 'localhost';
  constant PORT (line 3) | const PORT = '8000';

FILE: scripts/createdb.sql
  type User (line 4) | CREATE TABLE User
  type Story (line 10) | CREATE TABLE Story

FILE: server.js
  function graphQLHandler (line 8) | async function graphQLHandler(request, reply) {
  function runServer (line 22) | async function runServer() {
Condensed preview — 12 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (20K chars).
[
  {
    "path": ".babelrc",
    "chars": 17,
    "preview": "{\n  \"stage\": 1\n}\n"
  },
  {
    "path": ".eslintrc",
    "chars": 1068,
    "preview": "{\n  \"parser\": \"babel-eslint\",\n  \"env\": {\n    \"node\": true,\n    \"mocha\": true\n  },\n  \"rules\": {\n    \"brace-style\": 2,\n   "
  },
  {
    "path": ".gitignore",
    "chars": 538,
    "preview": "# Logs\nlogs\n*.log\n\n# Runtime data\npids\n*.pid\n*.seed\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nl"
  },
  {
    "path": "LICENSE",
    "chars": 1092,
    "preview": "The MIT License (MIT)\n\nCopyright (c) 2015-present, Reindex Software\n\nPermission is hereby granted, free of charge, to an"
  },
  {
    "path": "README.md",
    "chars": 307,
    "preview": "# graphql-nodejs-newsfeed\nExample of graphql nodejs backend with newsfeed, built with hapi and sqlite\n\n## Set Up Databas"
  },
  {
    "path": "Schema.js",
    "chars": 1802,
    "preview": "import {\n  GraphQLSchema,\n  GraphQLObjectType,\n  GraphQLID,\n  GraphQLString,\n  GraphQLNonNull,\n  GraphQLList\n} from 'gra"
  },
  {
    "path": "SqlitePlugin.js",
    "chars": 719,
    "preview": "import sqlite3 from 'sqlite3';\nimport {DB_PATH} from './config';\nimport {promisify} from 'bluebird';\n\nasync function ope"
  },
  {
    "path": "config.js",
    "chars": 100,
    "preview": "export const DB_PATH = './db.sqlite3';\nexport const HOST = 'localhost';\nexport const PORT = '8000';\n"
  },
  {
    "path": "index.js",
    "chars": 50,
    "preview": "require('babel/register');\nrequire('./server')();\n"
  },
  {
    "path": "package.json",
    "chars": 892,
    "preview": "{\n  \"name\": \"graphql-nodejs-newsfeed\",\n  \"version\": \"1.0.0\",\n  \"description\": \"Example of graphql nodejs backend with ne"
  },
  {
    "path": "scripts/createdb.sql",
    "chars": 11527,
    "preview": "DROP TABLE IF EXISTS Story;\nDROP TABLE IF EXISTS User;\n\nCREATE TABLE User\n(\n  id INTEGER PRIMARY KEY,\n  name VARCHAR(255"
  },
  {
    "path": "server.js",
    "chars": 1041,
    "preview": "import Hapi from 'hapi';\nimport {graphql} from 'graphql';\nimport {promisify} from 'bluebird';\nimport {HOST, PORT} from '"
  }
]

About this extraction

This page contains the full source code of the reindexio/graphql-nodejs-newsfeed GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 12 files (18.7 KB), approximately 5.1k tokens, and a symbol index with 15 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!