{"id":16296488,"url":"https://github.com/maticzav/graphql-server-file-upload-example","last_synced_at":"2025-03-20T04:31:21.022Z","repository":{"id":66336257,"uuid":"113656905","full_name":"maticzav/graphql-server-file-upload-example","owner":"maticzav","description":"💾 GraphQL Server examples: File API","archived":false,"fork":false,"pushed_at":"2022-06-26T07:58:11.000Z","size":83,"stargazers_count":21,"open_issues_count":1,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-28T23:10:41.398Z","etag":null,"topics":["bucket","fileupload","gateway","graphcool","graphql","graphql-gateway","schema-stitching"],"latest_commit_sha":null,"homepage":"http://medium.com/@maticzavadlal/graphcool-1-0-examples-series-file-api-3b16b4b8785f","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maticzav.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-12-09T09:13:31.000Z","updated_at":"2023-12-31T01:41:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"b68b944d-cb30-4241-8fda-ec963965a009","html_url":"https://github.com/maticzav/graphql-server-file-upload-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fgraphql-server-file-upload-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fgraphql-server-file-upload-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fgraphql-server-file-upload-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fgraphql-server-file-upload-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maticzav","download_url":"https://codeload.github.com/maticzav/graphql-server-file-upload-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244051969,"owners_count":20390007,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bucket","fileupload","gateway","graphcool","graphql","graphql-gateway","schema-stitching"],"created_at":"2024-10-10T20:22:54.580Z","updated_at":"2025-03-20T04:31:20.690Z","avatar_url":"https://github.com/maticzav.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GraphQL Server File Upload Example\n\nThis example illustrates the implementation of File API with GraphQL Server pattern. The best example for GraphQL Server basic usage can be found here: https://github.com/graphcool/graphql-server-example .\n\n## Getting Started\n\n### Initializing Prisma Database Service\n```sh\ngraphcool deploy # choose local cluster\n# copy API endpoint into the `PRISMA_ENPOINT` env var in .env\n```\n\nTo get `GRAPHCOOL_SECRET` visit http://jwtbuilder.jamiekurtz.com and scroll to the bottom where you can hash your secret from `graphcool.yml` and get the hashed output. (`sssh` is used in the example.)\n\n### Setting up the S3 bucket\n1. Head over to the [AWS console](http://console.aws.amazon.com/) and navigate to the `S3` section.\n2. Click create bucket and follow the instructions on screen.\n3. Once you have created a `bucket`, add bucket name that you've picked to .env `S3_BUCKET` property.\n4. Head back to the AWS Console and open `Identity and Access Management (IAM)` [console](https://console.aws.amazon.com/iam). Navigate to `Users` and click `Add user`.\n5. Under _Access type_ check **Programmatic access** and press `Next`. From options, select _Attach existing policies directly_ and a table below will open. Search for **AmazonS3FullAccess** and check it. Press `Next` to review everything and submit by pressing `Create user`.\n6. Once done, copy the _Access key ID_ to .env `S3_KEY` property and _Secret access key_ to .env `S3_SECRET` property.\n7. You are all set to start the server!\n\n### Starting the Server\n\n```sh\nyarn install\nyarn start\n# Open http://localhost:5000/\n```\n\n## Uploading files\n\nYou can upload files  to a project by doing a `multipart/form-data` HTTP request to the File API `http://localhost:5000/upload`.\n\nIt's important to use the form parameter `data` as seen in the example below.\n\n### Uploading workflow\n\nEverytime you upload a file to Prisma, a new `File` node is created that contains information about that file.\n\n* `id`: the [familiar system field](!alias-eiroozae8u#id-field)\n* `secret`: a unique, unguessable secret that allows access to the file\n* `name`: the file name\n* `size`: the file size\n* `url`: the url of the file where it can be accessed. The url contains of the project id and the file `secret`, so is unguessable as well.\n* `contentType`: the contentType of the file. It is determined based on the file name (extension in the name is required!).\n\nIf you want to connect the `File` node to another node in a relation, you can use the `id` in the response.\n\nWith `curl` you could execute:\n\n`curl -X POST 'http://localhost:5000/upload' -F \"data=@example.png; filename=coolimage.png\"`\n\nThis uploads the local file `example.png` under `coolimage.png` name. The response could look something like this:\n\n```JSON\n[{\n  \"id\": \"cjbqvp4ii00390181b1q0dq6h\",\n  \"name\": \"coolimage.png\",\n  \"secret\": \"43de4b08-78b2-4b5c-a5b7-05ee350ee09a\",\n  \"contentType\": \"image/png\",\n  \"size\": 36625,\n  \"url\": \"https://__S3_BUCKET__.s3-eu-west-1.amazonaws.com/43de4b08-78b2-4b5c-a5b7-05ee350ee09a\"\n}]\n```\n\n\u003e If there's no filename provided, the original name of the file is used instead.\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaticzav%2Fgraphql-server-file-upload-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaticzav%2Fgraphql-server-file-upload-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaticzav%2Fgraphql-server-file-upload-example/lists"}