Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
chore: add more settings (#1)
Browse files Browse the repository at this point in the history
* update README

* add chore settings

* fmt fix
  • Loading branch information
s-hirano-ist authored Oct 27, 2023
1 parent c22f74d commit 0f4e93f
Show file tree
Hide file tree
Showing 13 changed files with 366 additions and 231 deletions.
55 changes: 55 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:import/recommended",
"plugin:import/typescript",
"prettier",
],
parserOptions: {
ecmaVersion: "latest",
project: ["./tsconfig.json"],
},
rules: {
"@typescript-eslint/ban-ts-comment": "off",
"react/prop-types": "off",
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
"@typescript-eslint/no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
"import/order": [
"error",
{
groups: ["builtin", "external", "parent", "sibling", "index"],
pathGroupsExcludedImportTypes: [],
alphabetize: { order: "asc" },
"newlines-between": "never",
},
],
// FIXME: delete
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-explicit-any": "off",
},
root: true,
settings: {
"import/resolver": {
node: {
extensions: [".json", ".ts"],
moduleDirectory: ["node_modules", "src/"],
},
},
},
ignorePatterns: ["prisma/seed.ts"],
};
34 changes: 34 additions & 0 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
timezone: "Asia/Tokyo",
baseBranches: ["main"],
extends: ["config:base", ":semanticCommitTypeAll(chore)"],
enabledManagers: ["npm"],
dependencyDashboard: true,
schedule: ["before 11am every monday"],
automergeSchedule: ["before 11am every tuesday"],
labels: ["dependencies"],
rangeStrategy: "bump",
lockFileMaintenance: {
enabled: true,
automerge: true,
},
packageRules: [
{
matchManagers: ["npm"],
matchDepTypes: ["devDependencies"],
matchPackagePatterns: ["lint", "prettier"],
automerge: true,
},
{
matchManagers: ["npm"],
matchUpdateTypes: ["minor", "patch"],
matchCurrentVersion: "!/^0/",
automerge: true,
},
{
extends: ["monorepo:ionic-native"],
matchUpdateTypes: ["patch", "minor"],
automerge: true,
},
],
}
39 changes: 39 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: build
on:
push:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 20
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: "18"

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false

- name: Get pnpm directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-node-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-node-
- run: pnpm i --frozen-lockfile
- run: pnpm fmt
- run: pnpm lint
- run: pnpm build
17 changes: 8 additions & 9 deletions .markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"config": {
"line-length": false, // MD013 行の長さ
"no-bare-urls": false, // MD034 URLのリンク化条件
"no-duplicate-header": false,
"no-inline-html": false
},
"ignores": [".git", "node_modules"] // 無視するディレクトリ
}

"config": {
"line-length": false, // MD013 行の長さ
"no-bare-urls": false, // MD034 URLのリンク化条件
"no-duplicate-header": false,
"no-inline-html": false
},
"ignores": [".git", "node_modules"] // 無視するディレクトリ
}
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/*
pnpm-lock.yaml
68 changes: 27 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sample Apollo Server Project
# RSS dumper GraphQL

## Tech Stack

Expand All @@ -8,15 +8,14 @@

> https://github.com/prisma/prisma-examples/tree/latest/typescript/graphql-nexus

# GraphQL Server Example

This example shows how to implement a **GraphQL server with TypeScript** with the following stack:

- [**Apollo Server**](https://github.com/apollographql/apollo-server): HTTP server for GraphQL APIs
- [**GraphQL Nexus**](https://nexusjs.org/docs/): GraphQL schema definition and resolver implementation
- [**Prisma Client**](https://www.prisma.io/docs/concepts/components/prisma-client): Databases access (ORM)
- [**Prisma Migrate**](https://www.prisma.io/docs/concepts/components/prisma-migrate): Database migrations
- [**Apollo Server**](https://github.com/apollographql/apollo-server): HTTP server for GraphQL APIs
- [**GraphQL Nexus**](https://nexusjs.org/docs/): GraphQL schema definition and resolver implementation
- [**Prisma Client**](https://www.prisma.io/docs/concepts/components/prisma-client): Databases access (ORM)
- [**Prisma Migrate**](https://www.prisma.io/docs/concepts/components/prisma-migrate): Database migrations
- [**SQLite**](https://www.sqlite.org/index.html): Local, file-based SQL database

## Contents
Expand Down Expand Up @@ -71,7 +70,6 @@ npx prisma migrate dev --name init

When `npx prisma migrate dev` is executed against a newly created database, seeding is also triggered. The seed file in [`prisma/seed.ts`](./prisma/seed.ts) will be executed and your database will be populated with the sample data.


### 3. Start the GraphQL server

Launch your GraphQL server with this command:
Expand All @@ -82,7 +80,6 @@ npm run dev

Navigate to [http://localhost:4000](http://localhost:4000) in your browser to explore the API of your GraphQL server in a [GraphQL Playground](https://github.com/prisma/graphql-playground).


## Using the GraphQL API

The schema that specifies the API operations of your GraphQL server is defined in [`./schema.graphql`](./schema.graphql). Below are a number of operations that you can send to the API using the GraphQL Playground.
Expand Down Expand Up @@ -113,11 +110,7 @@ query {

```graphql
{
draftsByUser(
userUniqueInput: {
email: "mahmoud@prisma.io"
}
) {
draftsByUser(userUniqueInput: { email: "mahmoud@prisma.io" }) {
id
title
content
Expand All @@ -131,7 +124,6 @@ query {
}
```


### Create a new user

```graphql
Expand Down Expand Up @@ -209,9 +201,7 @@ mutation {

```graphql
{
feed(
searchString: "prisma"
) {
feed(searchString: "prisma") {
id
title
content
Expand All @@ -224,11 +214,7 @@ mutation {

```graphql
{
feed(
skip: 2
take: 2
orderBy: { updatedAt: desc }
) {
feed(skip: 2, take: 2, orderBy: { updatedAt: desc }) {
id
updatedAt
title
Expand All @@ -242,7 +228,7 @@ mutation {

```graphql
{
postById(id: __POST_ID__ ) {
postById(id: __POST_ID__) {
id
title
content
Expand All @@ -255,7 +241,7 @@ Note that you need to replace the `__POST_ID__` placeholder with an actual `id`

```graphql
{
postById(id: 5 ) {
postById(id: 5) {
id
title
content
Expand Down Expand Up @@ -386,8 +372,8 @@ const User = objectType({
+ type: 'Profile',
+ resolve: (parent, _, context) => {
+ return context.prisma.user
+ .findUnique({
+ where: { id: parent.id },
+ .findUnique({
+ where: { id: parent.id },
+ })
+ .profile();
+ },
Expand Down Expand Up @@ -438,7 +424,7 @@ const Mutation = objectType({
+ }),
+ ),
+ bio: stringArg()
+ },
+ },
+ resolve: async (_, args, context) => {
+ return context.prisma.profile.create({
+ data: {
Expand All @@ -463,9 +449,7 @@ Finally, you can test the new mutation like this:
```graphql
mutation {
addProfileForUser(
userUniqueInput: {
email: "mahmoud@prisma.io"
}
userUniqueInput: { email: "mahmoud@prisma.io" }
bio: "I like turtles"
) {
id
Expand All @@ -487,50 +471,50 @@ Here are some more sample Prisma Client queries on the new <code>Profile</code>
```ts
const profile = await prisma.profile.create({
data: {
bio: 'Hello World',
bio: "Hello World",
user: {
connect: { email: 'alice@prisma.io' },
connect: { email: "alice@prisma.io" },
},
},
})
});
```

##### Create a new user with a new profile

```ts
const user = await prisma.user.create({
data: {
email: 'john@prisma.io',
name: 'John',
email: "john@prisma.io",
name: "John",
profile: {
create: {
bio: 'Hello World',
bio: "Hello World",
},
},
},
})
});
```

##### Update the profile of an existing user

```ts
const userWithUpdatedProfile = await prisma.user.update({
where: { email: 'alice@prisma.io' },
where: { email: "alice@prisma.io" },
data: {
profile: {
update: {
bio: 'Hello Friends',
bio: "Hello Friends",
},
},
},
})
});
```

</details>

## Switch to another database (e.g. PostgreSQL, MySQL, SQL Server, MongoDB)

If you want to try this example with another database than SQLite, you can adjust the the database connection in [`prisma/schema.prisma`](./prisma/schema.prisma) by reconfiguring the `datasource` block.
If you want to try this example with another database than SQLite, you can adjust the the database connection in [`prisma/schema.prisma`](./prisma/schema.prisma) by reconfiguring the `datasource` block.

Learn more about the different connection configurations in the [docs](https://www.prisma.io/docs/reference/database-reference/connection-urls).

Expand Down Expand Up @@ -597,6 +581,7 @@ datasource db {
url = "mongodb://USERNAME:PASSWORD@HOST/DATABASE?authSource=admin&retryWrites=true&w=majority"
}
```

Because MongoDB is currently in [Preview](https://www.prisma.io/docs/about/releases#preview), you need to specify the `previewFeatures` on your `generator` block:

```
Expand All @@ -605,6 +590,7 @@ generator client {
previewFeatures = ["mongodb"]
}
```

</details>

## Next steps
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"dev": "ts-node-dev --no-notify --respawn --transpile-only src/server",
"start": "node dist/server",
"build": "npm -s run clean && npm -s run generate && tsc",
"build": "npm -s run clean && npm -s run generate && tsc",
"check:types": "tsc --noEmit",
"fmt": "prettier --check .",
"fmt:fix": "prettier --write .",
Expand Down
Loading

0 comments on commit 0f4e93f

Please sign in to comment.