Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs being sourced locally again #81

Merged
merged 4 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ yarn-error.log*
.yarn/

.idea/
src/*/*.json
/docs
src/*/*.json
208 changes: 208 additions & 0 deletions docs/getting_started/configuration.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
---
title: Configuration
sidebar_position: 2
---

import Tabs from "@theme/Tabs"
import TabItem from "@theme/TabItem"

For our first example, we are going to compose a GraphQL schema from the REST APIs at <a href="https://jsonplaceholder.typicode.com" target="_blank">https://jsonplaceholder.typicode.com</a>, a free online REST API with some fake data.
We will use the API at `/users` to get a list of users, and `/users/:id/posts` to get the posts for each user, and compose them into a single GraphQL schema.

We can use the following formats to define our GraphQL schema: `.graphql`, `.yml`, `.json`.

Create one of the following files and paste the contents into it.

<Tabs>
<TabItem value="graphql" label="graphql">

`jsonplaceholder.graphql`

```graphql showLineNumbers
schema
# Specify server configuration: Start tailcall server at 0.0.0.0:8000 and enable GraphiQL playground
@server(port: 8000, graphiql: true)
# Specify a base url for all http requests
@upstream(baseURL: "http://jsonplaceholder.typicode.com") {
query: Query
}

type Query {
# Specify the http path for the users query
users: [User] @http(path: "/users")
}

# Create a user type with the fields returned by the users api
type User {
id: Int!
name: String!
username: String!
email: String!

# Extend the user type with the posts field
# Use the current user's id to construct the path
posts: [Post] @http(path: "/users/{{value.id}}/posts")
}

# Create a post type with the fields returned by the posts api
type Post {
id: Int!
title: String!
body: String!
}
```

</TabItem>
<TabItem value="yml" label="yml">

`jsonplaceholder.yml`

```yml showLineNumbers
server:
port: 8000
graphiql: true
queryValidation: false
hostname: "0.0.0.0"
upstream:
baseURL: "http://jsonplaceholder.typicode.com"
httpCache: true
schema:
query: Query
types:
Post:
fields:
body:
type: String
required: true
id:
type: Int
required: true
title:
type: String
required: true
user:
type: User
http:
path: /users/{{value.userId}}
userId:
type: Int
required: true
Query:
fields:
posts:
type: Post
list: true
http:
path: /posts
User:
fields:
email:
type: String
required: true
id:
type: Int
required: true
name:
type: String
required: true
phone:
type: String
username:
type: String
required: true
website:
type: String
```

</TabItem>
<TabItem value="json" label="json">

`jsonplaceholder.json`

```json showLineNumbers
{
"server": {
"port": 8000,
"graphiql": true,
"queryValidation": false,
"hostname": "0.0.0.0"
},
"upstream": {
"baseURL": "http://jsonplaceholder.typicode.com",
"httpCache": true
},
"schema": {
"query": "Query"
},
"types": {
"Post": {
"fields": {
"body": {
"type": "String",
"required": true
},
"id": {
"type": "Int",
"required": true
},
"title": {
"type": "String",
"required": true
},
"user": {
"type": "User",
"http": {
"path": "/users/{{value.userId}}"
}
},
"userId": {
"type": "Int",
"required": true
}
}
},
"Query": {
"fields": {
"posts": {
"type": "Post",
"list": true,
"http": {
"path": "/posts"
}
}
}
},
"User": {
"fields": {
"email": {
"type": "String",
"required": true
},
"id": {
"type": "Int",
"required": true
},
"name": {
"type": "String",
"required": true
},
"phone": {
"type": "String"
},
"username": {
"type": "String",
"required": true
},
"website": {
"type": "String"
}
}
}
}
}
```

</TabItem>
</Tabs>

The above file is a standard `.graphQL` file, with a few additions such as `@upstream` and `@http` directives. So basically we specify the GraphQL schema and how to resolve that GraphQL schema in the same file, without having to write any code!
56 changes: 56 additions & 0 deletions docs/getting_started/execute.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
title: Execute
sidebar_position: 4
---

1. Open a web browser and go to [http://localhost:8000](http://localhost:8000). This should load the GraphiQL interface.
2. In the query editor of GraphiQL, enter the following query

```graphql showLineNumbers
query {
users {
id
name
posts {
title
}
}
}
```

3. After running the query in GraphiQL, expect to see a JSON response structured like this:

```json showLineNumbers
{
"data": {
"users": [
{
"id": 1,
"name": "Leanne Graham",
"posts": [
{
"title": "sunt aut facere repellat provident occaecati excepturi option reprehenderit"
}
// Additional posts truncated for brevity
]
},
{
"id": 2,
"name": "Ervin Howell",
"posts": [
{
"title": "et ea vero quia laudantium autem"
},
{
"title": "in quibusdam tempore odit est dolorem"
}
// Additional posts truncated for brevity
]
}
// Additional users truncated for brevity
]
}
}
```

You can now add additional fields, and compose more queries together!
100 changes: 100 additions & 0 deletions docs/getting_started/installation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
title: Installation
sidebar_position: 1
slug: /getting_started
---

import CodeBlock from "@theme/CodeBlock"
import Version from "../../src/components/Version"
import InstallCommand from "../../src/components/install"

<>
You can install the latest version -{" "}
**<Version />**, by using<b> NPM</b>.
</>
## NPM

1. If you don't already have **nodejs** installed, you can find the instructions [here](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs).
2. Install Tailcall by running the following command in your terminal:
```bash
npm i -g @tailcallhq/tailcall
```
3. Verify that Tailcall is installed correctly by running:

```bash
tailcall
```

:::note
Do not use the `--force` flag during npm installations, as it ignores installing platform-specific builds.
:::

## Yarn

1. Install Tailcall by running the following command in your terminal:
```bash
yarn global add @tailcallhq/tailcall
```
2. Verify that Tailcall is installed correctly by running:

```bash
tailcall
```

## Homebrew

1. If you don't already have Homebrew installed, you can find the instructions [here](https://brew.sh/).

2. Add the Tailcall repository to Homebrew by running the following command in your terminal:
```bash
brew tap tailcallhq/tailcall
brew install tailcall
```
3. Verify that Tailcall is installed correctly by running:

```bash
tailcall
```

4. Once installation is done, **upgrades** can be performed via:

```bash
brew update
brew upgrade tailcall
```

## Curl

Follow the steps below to manually install the cli on your system:

<InstallCommand />

This command fetches and executes the Tailcall installation script. The installed files are located in the `~/.tailcall` directory.

Upon completion of the installation, extend your `PATH` environment variable to include the `~/.tailcall/bin` directory:

```bash
export PATH=$PATH:~/.tailcall/bin
```

## Docker

If you want to install Tailcall with Docker, follow the steps below. Before starting, ensure Docker is installed on your system. If not, you can download it from [here](https://www.docker.com/products/docker-desktop).

1. Pull the latest Tailcall Docker image using the following command:

<CodeBlock language="bash">
docker pull tailcall.docker.scarf.sh/tailcallhq/tailcall/tc-server:
<Version />
</CodeBlock>

This command fetches the latest version of the Tailcall Docker image from the Docker registry.

2. Run the Tailcall Docker container with the following command:

<CodeBlock language="bash">
docker run -p 8080:8080 -p 8081:8081 tailcall.docker.scarf.sh/tailcallhq/tailcall/tc-server:
<Version />
</CodeBlock>

This command starts the Tailcall server in a Docker container. Similar to the homebrew installation, it exposes a the graphQL endpoint on port 8080.
Loading