Git Product home page Git Product logo

express-graphql-example's Introduction

Express, GraphQL example

License codecov

out

How to run the project using Docker

docker-compose up --build

Open GraphiQL in your browser http://localhost:3010/graphql

How to run the project

Install dependencies:

yarn

# or using npm

npm install

Create src/config.ts or rename src/config.example.js and update file with your credentials:

export default {
  port: 3010,
  database: {
    type: 'mysql',
    connection: {
      database : '',
      host : '',
      password : '',
      user : '',
    },
    /*
     * Migrations run on every start of the application.
     * If you initialized the database manually (from the database.sql file),
     * you don't need this.
     */
    migrations: {
      directory: __dirname + '/migrations',
    },
  },
};

Run the project:

yarn start

# or using npm

npm start

Open GraphiQL in your browser http://localhost:3010/graphql

Examples

You can find example queries in EXAMPLES.md.

Old version

Here is a link to an old version, that used sequelize and did not use connections:

Here is a link to older version, that did not use typescript, and used buildSchema method and graphql schema file:

Here is a link to older version, that used typescript version 4.x and graphql-express package to handle GrahpQL requests:

License

MIT license

express-graphql-example's People

Contributors

eric-hc avatar jakubbt avatar juffalow avatar kunal-mandalia avatar thinkingmik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

express-graphql-example's Issues

Create version 2

What to change:

  • variable names ( last_name => lastName )
  • change pagination ( to use edges and nodes )
  • add permissions ( public user / admin )

Add JWT auth

Add basic auth functionality. Any user can read the data - query authors and quotes but only logged in user can add new author / use mutations.

Improve queries

Because of #13 now it always loads everything from the database, even if it is not requested. This can be optimized also.

How to Improve Performance?

Hey, Thanks a lot for the wonderful project.
But I have some reservations, hope you could address them.

query{
  authors{
    name
    last_name
      quotes{
        id
        quote
      }
  }
}

Query like above will have performance issues, since numerous requests are made to the Database.
Example:

Executing (default): SELECT [id], [name], [last_name] FROM [author] AS [author];
Executing (default): SELECT [id], [name], [last_name] FROM [author] AS [author];
Executing (default): SELECT [id], [name], [last_name] FROM [author] AS [author];
Executing (default): SELECT [id], [name], [last_name] FROM [author] AS [author];
Executing (default): SELECT [id], [author_id], [quote] FROM [quote] AS [quote] WHERE [quote].[author_id] = 1;
Executing (default): SELECT [id], [author_id], [quote] FROM [quote] AS [quote] WHERE [quote].[author_id] = 2;
Executing (default): SELECT [id], [author_id], [quote] FROM [quote] AS [quote] WHERE [quote].[author_id] = 3;
Executing (default): SELECT [id], [author_id], [quote] FROM [quote] AS [quote] WHERE [quote].[author_id] = 4;
Executing (default): SELECT [id], [author_id], [quote] FROM [quote] AS [quote] WHERE [quote].[author_id] = 5;
Executing (default): SELECT [id], [author_id], [quote] FROM [quote] AS [quote] WHERE [quote].[author_id] = 6;

So, rather than querying DB once, n+1 requests are made.
One to retrieve all the users and n to retrieve quotes for each of the author.
Do you have any recommendations how to improve that and minimize the number of SQL round-trips?

Any examples to use the filter on authors' query

Tried

{
authors(filter: {name: "Bill"}) {
id
last_name
name
}
}

Got the error:

{
"errors": [
{
"message": "Invalid value { name: 'Bill' }",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"authors"
]
}
],
"data": {
"authors": null
}
}

Thanks for help with this very good example application.

Mutation for update and delete

How I can do delete and update data with the mutation? And why query doesnt result data but can insert to the database? Sorry for bad english

createAuthor returns error, though the record was created in the database.

Ran the test case:
mutation {
createAuthor(author: {
name: "Kent",
last_name: "Beck"
}) {
id
}
}

Got the following error. The record actually was created in the database.

{
"errors": [
{
"message": "Cannot read property 'forEach' of undefined",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"createAuthor"
]
}
],
"data": {
"createAuthor": null
}
}

Add tests

It should have at least some tests.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.