├── .flowconfig ├── .gitignore ├── LICENSE ├── README.md ├── graphql.config.json ├── package.json ├── public ├── favicon.ico ├── index.html └── manifest.json ├── schema.graphql ├── setup.js ├── src ├── App.js ├── Environment.js ├── MainRelay.js ├── __generated__ │ └── MainRelayQuery.graphql.js ├── components │ ├── Header.js │ ├── UserProfile.js │ ├── UserVisitCard.js │ └── __generated__ │ │ ├── UserProfile_User.graphql.js │ │ └── UserVisitCard_User.graphql.js ├── index.js ├── res │ ├── index.css │ ├── react_logo.svg │ └── relay_logo.svg └── sw │ └── registerServiceWorker.js └── yarn.lock /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ./node_modules/fbjs/.* 3 | 4 | [libs] 5 | ./flow-typed 6 | 7 | [options] 8 | esproposal.class_static_fields=enable 9 | esproposal.class_instance_fields=enable 10 | 11 | module.name_mapper='^\(.*\)\.css$' -> 'react-scripts/config/flow/css' 12 | module.name_mapper='^\(.*\)\.\(jpg\|png\|gif\|eot\|svg\|ttf\|woff\|woff2\|mp4\|webm\)$' -> 'react-scripts/config/flow/file' 13 | 14 | suppress_type=$FlowIssue 15 | suppress_type=$FlowFixMe 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # See https://help.github.com/ignore-files/ for more about ignoring files. 61 | 62 | # dependencies 63 | /node_modules 64 | 65 | # testing 66 | /coverage 67 | 68 | # production 69 | /build 70 | 71 | # misc 72 | .DS_Store 73 | .env.local 74 | .env.development.local 75 | .env.test.local 76 | .env.production.local 77 | 78 | npm-debug.log* 79 | yarn-debug.log* 80 | yarn-error.log* 81 | 82 | # IDE 83 | /.idea -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # relay 2 | Kit para Iniciantes no Relay Modern (baseado no create-react-app) 3 | 4 | # Antes de qualquer coisa 5 | Entre no Slack do React Brasil: [https://react-brasil-slack.herokuapp.com](https://react-brasil-slack.herokuapp.com) 6 | 7 | 8 | # Como rodar 9 | ```sh 10 | 11 | yarn install 12 | 13 | # Em uma aba 14 | yarn relay 15 | 16 | # Em outra aba 17 | yarn start 18 | 19 | ``` 20 | 21 | # Desafios 22 | - Mostrar a lista de usuários 23 | - Fazer com que mude o "user_id" mostrado atualmente ao clicar em um item na lista 24 | - Fazer uma chamada de mutation para editar o usuário 25 | - Abrir issues e pull-requests aqui, com melhorias para o kit de iniciantes no Relay Modern :) 26 | 27 | 28 | # Links úteis 29 | - [https://www.slideshare.net/reactconfbr/sibelius-seraphini-relay-modern](https://www.slideshare.net/reactconfbr/sibelius-seraphini-relay-modern) 30 | - [https://facebook.github.io/relay/docs/en/thinking-in-relay.html](https://facebook.github.io/relay/docs/en/thinking-in-relay.html) 31 | -------------------------------------------------------------------------------- /graphql.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": { 3 | "READ_FROM_file": "graphql.schema.json", 4 | "request": { 5 | "url" : "https://api.graph.cool/relay/v1/cjb3n7jnp0ir70184sgit9e4v", 6 | "method" : "POST", 7 | "postIntrospectionQuery" : true 8 | } 9 | }, 10 | "endpoints" : [ 11 | { 12 | "name": "Default (graph.cool)", 13 | "url": "https://api.graph.cool/relay/v1/cjb3n7jnp0ir70184sgit9e4v" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "relay", 3 | "version": "0.1.0", 4 | "private": false, 5 | "author": "nic", 6 | "contributors": [ 7 | "danvitoriano", 8 | "sibelius" 9 | ], 10 | "dependencies": { 11 | "react": "^16.2.0", 12 | "react-dom": "^16.2.0", 13 | "react-relay": "^1.4.1", 14 | "relay-runtime": "^1.4.1" 15 | }, 16 | "devDependencies": { 17 | "babel-plugin-relay": "^1.4.1", 18 | "react-scripts": "1.0.17", 19 | "relay-compiler": "^1.4.1" 20 | }, 21 | "scripts": { 22 | "relay": "relay-compiler --src ./src --schema ./schema.graphql --watch", 23 | "start": "./setup.js && react-scripts start", 24 | "build": "./setup.js && react-scripts build", 25 | "test": "./setup.js && react-scripts test --env=jsdom", 26 | "eject": "react-scripts eject" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nic/relay/1830c79fdd9a17f0344a849ebba9ece80c500fe3/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | React+Relay App 10 | 11 | 12 | 15 |
16 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /schema.graphql: -------------------------------------------------------------------------------- 1 | input CreateFile { 2 | name: String! 3 | } 4 | 5 | input CreateFileInput { 6 | name: String! 7 | clientMutationId: String! 8 | } 9 | 10 | type CreateFilePayload { 11 | viewer: Viewer! 12 | clientMutationId: String! 13 | file: File 14 | edge: FileEdge 15 | } 16 | 17 | input CreateUser { 18 | github: String! 19 | name: String! 20 | } 21 | 22 | # If authentication was successful the payload contains the user and a token. If unsuccessful this payload is null. 23 | type CreateUserPayload { 24 | user: User 25 | clientMutationId: String 26 | viewer: Viewer! 27 | } 28 | 29 | scalar DateTime 30 | 31 | input DeleteFileInput { 32 | id: ID! 33 | clientMutationId: String! 34 | } 35 | 36 | type DeleteFilePayload { 37 | viewer: Viewer! 38 | clientMutationId: String! 39 | file: File 40 | edge: FileEdge 41 | deletedId: ID 42 | } 43 | 44 | input DeleteUserInput { 45 | id: ID! 46 | clientMutationId: String! 47 | } 48 | 49 | type DeleteUserPayload { 50 | viewer: Viewer! 51 | clientMutationId: String! 52 | user: User 53 | edge: UserEdge 54 | deletedId: ID 55 | } 56 | 57 | type File implements Node { 58 | contentType: String! 59 | createdAt: DateTime! 60 | id: ID! 61 | name: String! 62 | secret: String! 63 | size: Int! 64 | updatedAt: DateTime! 65 | url: String! 66 | } 67 | 68 | # A connection to a list of items. 69 | type FileConnection { 70 | # Information to aid in pagination. 71 | pageInfo: PageInfo! 72 | 73 | # A list of edges. 74 | edges: [FileEdge] 75 | 76 | # Count of filtered result set without considering pagination arguments 77 | count: Int! 78 | } 79 | 80 | # An edge in a connection. 81 | type FileEdge { 82 | # The item at the end of the edge. 83 | node: File! 84 | 85 | # A cursor for use in pagination. 86 | cursor: String! 87 | } 88 | 89 | input FileFilter { 90 | # Logical AND on all given filters. 91 | AND: [FileFilter!] 92 | 93 | # Logical OR on all given filters. 94 | OR: [FileFilter!] 95 | contentType: String 96 | 97 | # All values that are not equal to given value. 98 | contentType_not: String 99 | 100 | # All values that are contained in given list. 101 | contentType_in: [String!] 102 | 103 | # All values that are not contained in given list. 104 | contentType_not_in: [String!] 105 | 106 | # All values less than the given value. 107 | contentType_lt: String 108 | 109 | # All values less than or equal the given value. 110 | contentType_lte: String 111 | 112 | # All values greater than the given value. 113 | contentType_gt: String 114 | 115 | # All values greater than or equal the given value. 116 | contentType_gte: String 117 | 118 | # All values containing the given string. 119 | contentType_contains: String 120 | 121 | # All values not containing the given string. 122 | contentType_not_contains: String 123 | 124 | # All values starting with the given string. 125 | contentType_starts_with: String 126 | 127 | # All values not starting with the given string. 128 | contentType_not_starts_with: String 129 | 130 | # All values ending with the given string. 131 | contentType_ends_with: String 132 | 133 | # All values not ending with the given string. 134 | contentType_not_ends_with: String 135 | createdAt: DateTime 136 | 137 | # All values that are not equal to given value. 138 | createdAt_not: DateTime 139 | 140 | # All values that are contained in given list. 141 | createdAt_in: [DateTime!] 142 | 143 | # All values that are not contained in given list. 144 | createdAt_not_in: [DateTime!] 145 | 146 | # All values less than the given value. 147 | createdAt_lt: DateTime 148 | 149 | # All values less than or equal the given value. 150 | createdAt_lte: DateTime 151 | 152 | # All values greater than the given value. 153 | createdAt_gt: DateTime 154 | 155 | # All values greater than or equal the given value. 156 | createdAt_gte: DateTime 157 | id: ID 158 | 159 | # All values that are not equal to given value. 160 | id_not: ID 161 | 162 | # All values that are contained in given list. 163 | id_in: [ID!] 164 | 165 | # All values that are not contained in given list. 166 | id_not_in: [ID!] 167 | 168 | # All values less than the given value. 169 | id_lt: ID 170 | 171 | # All values less than or equal the given value. 172 | id_lte: ID 173 | 174 | # All values greater than the given value. 175 | id_gt: ID 176 | 177 | # All values greater than or equal the given value. 178 | id_gte: ID 179 | 180 | # All values containing the given string. 181 | id_contains: ID 182 | 183 | # All values not containing the given string. 184 | id_not_contains: ID 185 | 186 | # All values starting with the given string. 187 | id_starts_with: ID 188 | 189 | # All values not starting with the given string. 190 | id_not_starts_with: ID 191 | 192 | # All values ending with the given string. 193 | id_ends_with: ID 194 | 195 | # All values not ending with the given string. 196 | id_not_ends_with: ID 197 | name: String 198 | 199 | # All values that are not equal to given value. 200 | name_not: String 201 | 202 | # All values that are contained in given list. 203 | name_in: [String!] 204 | 205 | # All values that are not contained in given list. 206 | name_not_in: [String!] 207 | 208 | # All values less than the given value. 209 | name_lt: String 210 | 211 | # All values less than or equal the given value. 212 | name_lte: String 213 | 214 | # All values greater than the given value. 215 | name_gt: String 216 | 217 | # All values greater than or equal the given value. 218 | name_gte: String 219 | 220 | # All values containing the given string. 221 | name_contains: String 222 | 223 | # All values not containing the given string. 224 | name_not_contains: String 225 | 226 | # All values starting with the given string. 227 | name_starts_with: String 228 | 229 | # All values not starting with the given string. 230 | name_not_starts_with: String 231 | 232 | # All values ending with the given string. 233 | name_ends_with: String 234 | 235 | # All values not ending with the given string. 236 | name_not_ends_with: String 237 | secret: String 238 | 239 | # All values that are not equal to given value. 240 | secret_not: String 241 | 242 | # All values that are contained in given list. 243 | secret_in: [String!] 244 | 245 | # All values that are not contained in given list. 246 | secret_not_in: [String!] 247 | 248 | # All values less than the given value. 249 | secret_lt: String 250 | 251 | # All values less than or equal the given value. 252 | secret_lte: String 253 | 254 | # All values greater than the given value. 255 | secret_gt: String 256 | 257 | # All values greater than or equal the given value. 258 | secret_gte: String 259 | 260 | # All values containing the given string. 261 | secret_contains: String 262 | 263 | # All values not containing the given string. 264 | secret_not_contains: String 265 | 266 | # All values starting with the given string. 267 | secret_starts_with: String 268 | 269 | # All values not starting with the given string. 270 | secret_not_starts_with: String 271 | 272 | # All values ending with the given string. 273 | secret_ends_with: String 274 | 275 | # All values not ending with the given string. 276 | secret_not_ends_with: String 277 | size: Int 278 | 279 | # All values that are not equal to given value. 280 | size_not: Int 281 | 282 | # All values that are contained in given list. 283 | size_in: [Int!] 284 | 285 | # All values that are not contained in given list. 286 | size_not_in: [Int!] 287 | 288 | # All values less than the given value. 289 | size_lt: Int 290 | 291 | # All values less than or equal the given value. 292 | size_lte: Int 293 | 294 | # All values greater than the given value. 295 | size_gt: Int 296 | 297 | # All values greater than or equal the given value. 298 | size_gte: Int 299 | updatedAt: DateTime 300 | 301 | # All values that are not equal to given value. 302 | updatedAt_not: DateTime 303 | 304 | # All values that are contained in given list. 305 | updatedAt_in: [DateTime!] 306 | 307 | # All values that are not contained in given list. 308 | updatedAt_not_in: [DateTime!] 309 | 310 | # All values less than the given value. 311 | updatedAt_lt: DateTime 312 | 313 | # All values less than or equal the given value. 314 | updatedAt_lte: DateTime 315 | 316 | # All values greater than the given value. 317 | updatedAt_gt: DateTime 318 | 319 | # All values greater than or equal the given value. 320 | updatedAt_gte: DateTime 321 | url: String 322 | 323 | # All values that are not equal to given value. 324 | url_not: String 325 | 326 | # All values that are contained in given list. 327 | url_in: [String!] 328 | 329 | # All values that are not contained in given list. 330 | url_not_in: [String!] 331 | 332 | # All values less than the given value. 333 | url_lt: String 334 | 335 | # All values less than or equal the given value. 336 | url_lte: String 337 | 338 | # All values greater than the given value. 339 | url_gt: String 340 | 341 | # All values greater than or equal the given value. 342 | url_gte: String 343 | 344 | # All values containing the given string. 345 | url_contains: String 346 | 347 | # All values not containing the given string. 348 | url_not_contains: String 349 | 350 | # All values starting with the given string. 351 | url_starts_with: String 352 | 353 | # All values not starting with the given string. 354 | url_not_starts_with: String 355 | 356 | # All values ending with the given string. 357 | url_ends_with: String 358 | 359 | # All values not ending with the given string. 360 | url_not_ends_with: String 361 | } 362 | 363 | enum FileOrderBy { 364 | contentType_ASC 365 | contentType_DESC 366 | createdAt_ASC 367 | createdAt_DESC 368 | id_ASC 369 | id_DESC 370 | name_ASC 371 | name_DESC 372 | secret_ASC 373 | secret_DESC 374 | size_ASC 375 | size_DESC 376 | updatedAt_ASC 377 | updatedAt_DESC 378 | url_ASC 379 | url_DESC 380 | } 381 | 382 | type Mutation { 383 | createFile(input: CreateFileInput!): CreateFilePayload 384 | updateFile(input: UpdateFileInput!): UpdateFilePayload 385 | updateUser(input: UpdateUserInput!): UpdateUserPayload 386 | updateOrCreateFile(input: UpdateOrCreateFileInput!): UpdateOrCreateFilePayload 387 | updateOrCreateUser(input: UpdateOrCreateUserInput!): UpdateOrCreateUserPayload 388 | deleteFile(input: DeleteFileInput!): DeleteFilePayload 389 | deleteUser(input: DeleteUserInput!): DeleteUserPayload 390 | createUser(input: SignupUserInput!): CreateUserPayload! 391 | } 392 | 393 | # An object with an ID 394 | interface Node { 395 | # The id of the object. 396 | id: ID! 397 | } 398 | 399 | # Information about pagination in a connection. 400 | type PageInfo { 401 | # When paginating forwards, are there more items? 402 | hasNextPage: Boolean! 403 | 404 | # When paginating backwards, are there more items? 405 | hasPreviousPage: Boolean! 406 | 407 | # When paginating backwards, the cursor to continue. 408 | startCursor: String 409 | 410 | # When paginating forwards, the cursor to continue. 411 | endCursor: String 412 | } 413 | 414 | type Query { 415 | viewer: Viewer! 416 | 417 | # Fetches an object given its ID 418 | node( 419 | # The ID of an object 420 | id: ID! 421 | ): Node 422 | } 423 | 424 | input SignupUserInput { 425 | github: String! 426 | name: String! 427 | clientMutationId: String! 428 | } 429 | 430 | input UpdateFile { 431 | id: ID! 432 | name: String 433 | } 434 | 435 | input UpdateFileInput { 436 | id: ID! 437 | name: String 438 | clientMutationId: String! 439 | } 440 | 441 | type UpdateFilePayload { 442 | viewer: Viewer! 443 | clientMutationId: String! 444 | file: File 445 | edge: FileEdge 446 | } 447 | 448 | input UpdateOrCreateFileInput { 449 | update: UpdateFile! 450 | create: CreateFile! 451 | clientMutationId: String! 452 | } 453 | 454 | type UpdateOrCreateFilePayload { 455 | viewer: Viewer! 456 | clientMutationId: String! 457 | file: File 458 | edge: FileEdge 459 | } 460 | 461 | input UpdateOrCreateUserInput { 462 | update: UpdateUser! 463 | create: CreateUser! 464 | clientMutationId: String! 465 | } 466 | 467 | type UpdateOrCreateUserPayload { 468 | viewer: Viewer! 469 | clientMutationId: String! 470 | user: User 471 | edge: UserEdge 472 | } 473 | 474 | input UpdateUser { 475 | github: String 476 | id: ID! 477 | name: String 478 | } 479 | 480 | input UpdateUserInput { 481 | github: String 482 | id: ID! 483 | name: String 484 | clientMutationId: String! 485 | } 486 | 487 | type UpdateUserPayload { 488 | viewer: Viewer! 489 | clientMutationId: String! 490 | user: User 491 | edge: UserEdge 492 | } 493 | 494 | type User implements Node { 495 | createdAt: DateTime! 496 | github: String! 497 | id: ID! 498 | name: String! 499 | updatedAt: DateTime! 500 | } 501 | 502 | # A connection to a list of items. 503 | type UserConnection { 504 | # Information to aid in pagination. 505 | pageInfo: PageInfo! 506 | 507 | # A list of edges. 508 | edges: [UserEdge] 509 | 510 | # Count of filtered result set without considering pagination arguments 511 | count: Int! 512 | } 513 | 514 | # An edge in a connection. 515 | type UserEdge { 516 | # The item at the end of the edge. 517 | node: User! 518 | 519 | # A cursor for use in pagination. 520 | cursor: String! 521 | } 522 | 523 | input UserFilter { 524 | # Logical AND on all given filters. 525 | AND: [UserFilter!] 526 | 527 | # Logical OR on all given filters. 528 | OR: [UserFilter!] 529 | createdAt: DateTime 530 | 531 | # All values that are not equal to given value. 532 | createdAt_not: DateTime 533 | 534 | # All values that are contained in given list. 535 | createdAt_in: [DateTime!] 536 | 537 | # All values that are not contained in given list. 538 | createdAt_not_in: [DateTime!] 539 | 540 | # All values less than the given value. 541 | createdAt_lt: DateTime 542 | 543 | # All values less than or equal the given value. 544 | createdAt_lte: DateTime 545 | 546 | # All values greater than the given value. 547 | createdAt_gt: DateTime 548 | 549 | # All values greater than or equal the given value. 550 | createdAt_gte: DateTime 551 | github: String 552 | 553 | # All values that are not equal to given value. 554 | github_not: String 555 | 556 | # All values that are contained in given list. 557 | github_in: [String!] 558 | 559 | # All values that are not contained in given list. 560 | github_not_in: [String!] 561 | 562 | # All values less than the given value. 563 | github_lt: String 564 | 565 | # All values less than or equal the given value. 566 | github_lte: String 567 | 568 | # All values greater than the given value. 569 | github_gt: String 570 | 571 | # All values greater than or equal the given value. 572 | github_gte: String 573 | 574 | # All values containing the given string. 575 | github_contains: String 576 | 577 | # All values not containing the given string. 578 | github_not_contains: String 579 | 580 | # All values starting with the given string. 581 | github_starts_with: String 582 | 583 | # All values not starting with the given string. 584 | github_not_starts_with: String 585 | 586 | # All values ending with the given string. 587 | github_ends_with: String 588 | 589 | # All values not ending with the given string. 590 | github_not_ends_with: String 591 | id: ID 592 | 593 | # All values that are not equal to given value. 594 | id_not: ID 595 | 596 | # All values that are contained in given list. 597 | id_in: [ID!] 598 | 599 | # All values that are not contained in given list. 600 | id_not_in: [ID!] 601 | 602 | # All values less than the given value. 603 | id_lt: ID 604 | 605 | # All values less than or equal the given value. 606 | id_lte: ID 607 | 608 | # All values greater than the given value. 609 | id_gt: ID 610 | 611 | # All values greater than or equal the given value. 612 | id_gte: ID 613 | 614 | # All values containing the given string. 615 | id_contains: ID 616 | 617 | # All values not containing the given string. 618 | id_not_contains: ID 619 | 620 | # All values starting with the given string. 621 | id_starts_with: ID 622 | 623 | # All values not starting with the given string. 624 | id_not_starts_with: ID 625 | 626 | # All values ending with the given string. 627 | id_ends_with: ID 628 | 629 | # All values not ending with the given string. 630 | id_not_ends_with: ID 631 | name: String 632 | 633 | # All values that are not equal to given value. 634 | name_not: String 635 | 636 | # All values that are contained in given list. 637 | name_in: [String!] 638 | 639 | # All values that are not contained in given list. 640 | name_not_in: [String!] 641 | 642 | # All values less than the given value. 643 | name_lt: String 644 | 645 | # All values less than or equal the given value. 646 | name_lte: String 647 | 648 | # All values greater than the given value. 649 | name_gt: String 650 | 651 | # All values greater than or equal the given value. 652 | name_gte: String 653 | 654 | # All values containing the given string. 655 | name_contains: String 656 | 657 | # All values not containing the given string. 658 | name_not_contains: String 659 | 660 | # All values starting with the given string. 661 | name_starts_with: String 662 | 663 | # All values not starting with the given string. 664 | name_not_starts_with: String 665 | 666 | # All values ending with the given string. 667 | name_ends_with: String 668 | 669 | # All values not ending with the given string. 670 | name_not_ends_with: String 671 | updatedAt: DateTime 672 | 673 | # All values that are not equal to given value. 674 | updatedAt_not: DateTime 675 | 676 | # All values that are contained in given list. 677 | updatedAt_in: [DateTime!] 678 | 679 | # All values that are not contained in given list. 680 | updatedAt_not_in: [DateTime!] 681 | 682 | # All values less than the given value. 683 | updatedAt_lt: DateTime 684 | 685 | # All values less than or equal the given value. 686 | updatedAt_lte: DateTime 687 | 688 | # All values greater than the given value. 689 | updatedAt_gt: DateTime 690 | 691 | # All values greater than or equal the given value. 692 | updatedAt_gte: DateTime 693 | } 694 | 695 | enum UserOrderBy { 696 | createdAt_ASC 697 | createdAt_DESC 698 | github_ASC 699 | github_DESC 700 | id_ASC 701 | id_DESC 702 | name_ASC 703 | name_DESC 704 | updatedAt_ASC 705 | updatedAt_DESC 706 | } 707 | 708 | # This is the famous Relay viewer object 709 | type Viewer { 710 | allFiles(filter: FileFilter, orderBy: FileOrderBy, skip: Int, after: String, before: String, first: Int, last: Int): FileConnection! 711 | allUsers(filter: UserFilter, orderBy: UserOrderBy, skip: Int, after: String, before: String, first: Int, last: Int): UserConnection! 712 | user: User 713 | File(id: ID, secret: String, url: String): File 714 | User(id: ID): User 715 | id: ID! 716 | } 717 | -------------------------------------------------------------------------------- /setup.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // by nic - 2017 –– 10 locs pra você não precisar dar eject 3 | 4 | const fs = require('fs'), 5 | file = require('path').resolve('./node_modules/babel-preset-react-app/index.js'), 6 | texts = fs.readFileSync(file, 'utf8'), 7 | plugin = 'babel-plugin-relay', 8 | pattern = 'const plugins = ['; 9 | 10 | if (!texts.includes(pattern)) throw new Error(`Failed to inject babel-plugin-relay.`); 11 | 12 | if (!texts.includes(plugin)) 13 | fs.writeFileSync(file, texts.replace(pattern, `${pattern}\n require.resolve('${plugin}'),`), 'utf8'); -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Header from './components/Header' 3 | import MainRelay from './MainRelay' 4 | 5 | const App = () => 6 |
7 |
8 |
9 | 10 |
11 |
; 12 | 13 | export default App; 14 | -------------------------------------------------------------------------------- /src/Environment.js: -------------------------------------------------------------------------------- 1 | import { Environment, Network, RecordSource, Store } from 'relay-runtime'; 2 | // Para habilitar a extensão do Google Chrome: 3 | // import { installRelayDevTools } from 'relay-devtools'; 4 | // installRelayDevTools(); 5 | 6 | function fetchQuery( 7 | operation, 8 | variables 9 | ) { 10 | return fetch( 11 | 'https://api.graph.cool/relay/v1/cjb3n7jnp0ir70184sgit9e4v', 12 | { 13 | method: 'POST', 14 | headers: {'content-type' : 'application/json'}, 15 | body: JSON.stringify({ 16 | query: operation.text, 17 | variables, 18 | }), 19 | }, 20 | ).then(response => response.json()); 21 | } 22 | 23 | const environment = new Environment({ 24 | network: Network.create(fetchQuery ), 25 | store: new Store(new RecordSource()), 26 | }); 27 | 28 | export default environment; 29 | -------------------------------------------------------------------------------- /src/MainRelay.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { QueryRenderer, graphql } from "react-relay"; 3 | import UserProfile from 'components/UserProfile' 4 | import UserVisitCard from 'components/UserVisitCard' 5 | 6 | import environment from './Environment'; 7 | 8 | const variables = { 9 | user_id: 'cjb3neu7x0rle01130wksqy9w' 10 | // user_id: 'cjb3ng15o2p4301066mw7bfjl' 11 | // user_id: 'cjb3nge9p0yqq0113vhc9clel' 12 | }; 13 | 14 | const query = graphql` 15 | query MainRelayQuery ($user_id:ID!) { 16 | viewer { 17 | User(id:$user_id) { 18 | ...UserProfile_User 19 | ...UserVisitCard_User 20 | } 21 | } 22 | } 23 | `; 24 | 25 | const MainRelay = ({viewer}) => 26 |
27 | 28 | 29 |
; 30 | 31 | export default () => { 37 | if (error) { 38 | return (Erro: {error}); 39 | } else if (props) { 40 | return (); 41 | } 42 | return (Carregando...); 43 | } 44 | } 45 | />; 46 | -------------------------------------------------------------------------------- /src/__generated__/MainRelayQuery.graphql.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @flow 3 | * @relayHash db5e3f2d6e01a5784bcb218aa73cfc79 4 | */ 5 | 6 | /* eslint-disable */ 7 | 8 | 'use strict'; 9 | 10 | /*:: 11 | import type {ConcreteBatch} from 'relay-runtime'; 12 | export type MainRelayQueryResponse = {| 13 | +viewer: {| 14 | +User: ?{| |}; 15 | |}; 16 | |}; 17 | */ 18 | 19 | 20 | /* 21 | query MainRelayQuery( 22 | $user_id: ID! 23 | ) { 24 | viewer { 25 | User(id: $user_id) { 26 | ...UserProfile_User 27 | ...UserVisitCard_User 28 | id 29 | } 30 | id 31 | } 32 | } 33 | 34 | fragment UserProfile_User on User { 35 | name 36 | } 37 | 38 | fragment UserVisitCard_User on User { 39 | name 40 | github 41 | } 42 | */ 43 | 44 | const batch /*: ConcreteBatch*/ = { 45 | "fragment": { 46 | "argumentDefinitions": [ 47 | { 48 | "kind": "LocalArgument", 49 | "name": "user_id", 50 | "type": "ID!", 51 | "defaultValue": null 52 | } 53 | ], 54 | "kind": "Fragment", 55 | "metadata": null, 56 | "name": "MainRelayQuery", 57 | "selections": [ 58 | { 59 | "kind": "LinkedField", 60 | "alias": null, 61 | "args": null, 62 | "concreteType": "Viewer", 63 | "name": "viewer", 64 | "plural": false, 65 | "selections": [ 66 | { 67 | "kind": "LinkedField", 68 | "alias": null, 69 | "args": [ 70 | { 71 | "kind": "Variable", 72 | "name": "id", 73 | "variableName": "user_id", 74 | "type": "ID" 75 | } 76 | ], 77 | "concreteType": "User", 78 | "name": "User", 79 | "plural": false, 80 | "selections": [ 81 | { 82 | "kind": "FragmentSpread", 83 | "name": "UserProfile_User", 84 | "args": null 85 | }, 86 | { 87 | "kind": "FragmentSpread", 88 | "name": "UserVisitCard_User", 89 | "args": null 90 | } 91 | ], 92 | "storageKey": null 93 | } 94 | ], 95 | "storageKey": null 96 | } 97 | ], 98 | "type": "Query" 99 | }, 100 | "id": null, 101 | "kind": "Batch", 102 | "metadata": {}, 103 | "name": "MainRelayQuery", 104 | "query": { 105 | "argumentDefinitions": [ 106 | { 107 | "kind": "LocalArgument", 108 | "name": "user_id", 109 | "type": "ID!", 110 | "defaultValue": null 111 | } 112 | ], 113 | "kind": "Root", 114 | "name": "MainRelayQuery", 115 | "operation": "query", 116 | "selections": [ 117 | { 118 | "kind": "LinkedField", 119 | "alias": null, 120 | "args": null, 121 | "concreteType": "Viewer", 122 | "name": "viewer", 123 | "plural": false, 124 | "selections": [ 125 | { 126 | "kind": "LinkedField", 127 | "alias": null, 128 | "args": [ 129 | { 130 | "kind": "Variable", 131 | "name": "id", 132 | "variableName": "user_id", 133 | "type": "ID" 134 | } 135 | ], 136 | "concreteType": "User", 137 | "name": "User", 138 | "plural": false, 139 | "selections": [ 140 | { 141 | "kind": "ScalarField", 142 | "alias": null, 143 | "args": null, 144 | "name": "name", 145 | "storageKey": null 146 | }, 147 | { 148 | "kind": "ScalarField", 149 | "alias": null, 150 | "args": null, 151 | "name": "github", 152 | "storageKey": null 153 | }, 154 | { 155 | "kind": "ScalarField", 156 | "alias": null, 157 | "args": null, 158 | "name": "id", 159 | "storageKey": null 160 | } 161 | ], 162 | "storageKey": null 163 | }, 164 | { 165 | "kind": "ScalarField", 166 | "alias": null, 167 | "args": null, 168 | "name": "id", 169 | "storageKey": null 170 | } 171 | ], 172 | "storageKey": null 173 | } 174 | ] 175 | }, 176 | "text": "query MainRelayQuery(\n $user_id: ID!\n) {\n viewer {\n User(id: $user_id) {\n ...UserProfile_User\n ...UserVisitCard_User\n id\n }\n id\n }\n}\n\nfragment UserProfile_User on User {\n name\n}\n\nfragment UserVisitCard_User on User {\n name\n github\n}\n" 177 | }; 178 | 179 | module.exports = batch; 180 | -------------------------------------------------------------------------------- /src/components/Header.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import react_logo from '../res/react_logo.svg'; 3 | import relay_logo from '../res/relay_logo.svg'; 4 | 5 | const Header = () => 6 |
7 | logo react 8 | logo relay 9 |

Bem-vindo ao React+Relay

10 |
; 11 | 12 | export default Header 13 | -------------------------------------------------------------------------------- /src/components/UserProfile.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { createFragmentContainer, graphql } from 'react-relay'; 3 | 4 | const UserProfile = ({User}) => 5 |
6 | Perfil 7 |
8 | Nome: {User.name} 9 |
; 10 | 11 | 12 | export default createFragmentContainer(UserProfile, graphql` 13 | fragment UserProfile_User on User { 14 | name 15 | } 16 | `); 17 | -------------------------------------------------------------------------------- /src/components/UserVisitCard.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { createFragmentContainer, graphql } from 'react-relay'; 3 | 4 | const UserVisitCard = ({User}) => 5 |
6 | Cartão de visita 7 |
8 | Nome: {User.name}
9 | GitHub: {User.github} 10 |
; 11 | 12 | 13 | export default createFragmentContainer(UserVisitCard, graphql` 14 | fragment UserVisitCard_User on User { 15 | name 16 | github 17 | } 18 | `); 19 | -------------------------------------------------------------------------------- /src/components/__generated__/UserProfile_User.graphql.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @flow 3 | */ 4 | 5 | /* eslint-disable */ 6 | 7 | 'use strict'; 8 | 9 | /*:: 10 | import type {ConcreteFragment} from 'relay-runtime'; 11 | export type UserProfile_User = {| 12 | +name: string; 13 | |}; 14 | */ 15 | 16 | 17 | const fragment /*: ConcreteFragment*/ = { 18 | "argumentDefinitions": [], 19 | "kind": "Fragment", 20 | "metadata": null, 21 | "name": "UserProfile_User", 22 | "selections": [ 23 | { 24 | "kind": "ScalarField", 25 | "alias": null, 26 | "args": null, 27 | "name": "name", 28 | "storageKey": null 29 | } 30 | ], 31 | "type": "User" 32 | }; 33 | 34 | module.exports = fragment; 35 | -------------------------------------------------------------------------------- /src/components/__generated__/UserVisitCard_User.graphql.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @flow 3 | */ 4 | 5 | /* eslint-disable */ 6 | 7 | 'use strict'; 8 | 9 | /*:: 10 | import type {ConcreteFragment} from 'relay-runtime'; 11 | export type UserVisitCard_User = {| 12 | +name: string; 13 | +github: string; 14 | |}; 15 | */ 16 | 17 | 18 | const fragment /*: ConcreteFragment*/ = { 19 | "argumentDefinitions": [], 20 | "kind": "Fragment", 21 | "metadata": null, 22 | "name": "UserVisitCard_User", 23 | "selections": [ 24 | { 25 | "kind": "ScalarField", 26 | "alias": null, 27 | "args": null, 28 | "name": "name", 29 | "storageKey": null 30 | }, 31 | { 32 | "kind": "ScalarField", 33 | "alias": null, 34 | "args": null, 35 | "name": "github", 36 | "storageKey": null 37 | } 38 | ], 39 | "type": "User" 40 | }; 41 | 42 | module.exports = fragment; 43 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './res/index.css'; 4 | import App from './App'; 5 | import registerServiceWorker from './sw/registerServiceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | registerServiceWorker(); 9 | -------------------------------------------------------------------------------- /src/res/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: sans-serif; 5 | } 6 | 7 | .App { 8 | text-align: center; 9 | } 10 | 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | height: 80px; 14 | } 15 | 16 | .App-header { 17 | background-color: #222; 18 | height: 150px; 19 | padding: 20px; 20 | color: white; 21 | } 22 | 23 | .App-title { 24 | font-size: 1.5em; 25 | } 26 | 27 | .App-intro { 28 | font-size: large; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { transform: rotate(0deg); } 33 | to { transform: rotate(360deg); } 34 | } 35 | 36 | .Box { 37 | flex: 1; 38 | align-content: space-between; 39 | } 40 | 41 | .Box-container { 42 | padding: 120px; 43 | display: flex; 44 | } 45 | 46 | .Box-border { 47 | border: 1px solid steelblue; 48 | } -------------------------------------------------------------------------------- /src/res/react_logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/res/relay_logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/sw/registerServiceWorker.js: -------------------------------------------------------------------------------- 1 | // In production, we register a service worker to serve assets from local cache. 2 | 3 | // This lets the app load faster on subsequent visits in production, and gives 4 | // it offline capabilities. However, it also means that developers (and users) 5 | // will only see deployed updates on the "N+1" visit to a page, since previously 6 | // cached resources are updated in the background. 7 | 8 | // To learn more about the benefits of this model, read https://goo.gl/KwvDNy. 9 | // This link also includes instructions on opting out of this behavior. 10 | 11 | const isLocalhost = Boolean( 12 | window.location.hostname === 'localhost' || 13 | // [::1] is the IPv6 localhost address. 14 | window.location.hostname === '[::1]' || 15 | // 127.0.0.1/8 is considered localhost for IPv4. 16 | window.location.hostname.match( 17 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 18 | ) 19 | ); 20 | 21 | export default function register() { 22 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 23 | // The URL constructor is available in all browsers that support SW. 24 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location); 25 | if (publicUrl.origin !== window.location.origin) { 26 | // Our service worker won't work if PUBLIC_URL is on a different origin 27 | // from what our page is served on. This might happen if a CDN is used to 28 | // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374 29 | return; 30 | } 31 | 32 | window.addEventListener('load', () => { 33 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 34 | 35 | if (isLocalhost) { 36 | // This is running on localhost. Lets check if a service worker still exists or not. 37 | checkValidServiceWorker(swUrl); 38 | } else { 39 | // Is not local host. Just register service worker 40 | registerValidSW(swUrl); 41 | } 42 | }); 43 | } 44 | } 45 | 46 | function registerValidSW(swUrl) { 47 | navigator.serviceWorker 48 | .register(swUrl) 49 | .then(registration => { 50 | registration.onupdatefound = () => { 51 | const installingWorker = registration.installing; 52 | installingWorker.onstatechange = () => { 53 | if (installingWorker.state === 'installed') { 54 | if (navigator.serviceWorker.controller) { 55 | // At this point, the old content will have been purged and 56 | // the fresh content will have been added to the cache. 57 | // It's the perfect time to display a "New content is 58 | // available; please refresh." message in your web app. 59 | console.log('New content is available; please refresh.'); 60 | } else { 61 | // At this point, everything has been precached. 62 | // It's the perfect time to display a 63 | // "Content is cached for offline use." message. 64 | console.log('Content is cached for offline use.'); 65 | } 66 | } 67 | }; 68 | }; 69 | }) 70 | .catch(error => { 71 | console.error('Error during service worker registration:', error); 72 | }); 73 | } 74 | 75 | function checkValidServiceWorker(swUrl) { 76 | // Check if the service worker can be found. If it can't reload the page. 77 | fetch(swUrl) 78 | .then(response => { 79 | // Ensure service worker exists, and that we really are getting a JS file. 80 | if ( 81 | response.status === 404 || 82 | response.headers.get('content-type').indexOf('javascript') === -1 83 | ) { 84 | // No service worker found. Probably a different app. Reload the page. 85 | navigator.serviceWorker.ready.then(registration => { 86 | registration.unregister().then(() => { 87 | window.location.reload(); 88 | }); 89 | }); 90 | } else { 91 | // Service worker found. Proceed as normal. 92 | registerValidSW(swUrl); 93 | } 94 | }) 95 | .catch(() => { 96 | console.log( 97 | 'No internet connection found. App is running in offline mode.' 98 | ); 99 | }); 100 | } 101 | 102 | export function unregister() { 103 | if ('serviceWorker' in navigator) { 104 | navigator.serviceWorker.ready.then(registration => { 105 | registration.unregister(); 106 | }); 107 | } 108 | } 109 | --------------------------------------------------------------------------------