This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
loop = asyncio.get_event_loop() | |
async def hello(): | |
await asyncio.sleep(3) | |
print('Hello!') | |
if __name__ == '__main__': | |
loop.run_until_complete(hello()) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/graphql/mutations/create_book.rb | |
module Mutations | |
class CreateBook < GraphQL::Schema::RelayClassicMutation | |
# define return fields (once book is created what can be returned) | |
field :book, Types::BookType, null: false | |
# define arguments required to create a book | |
# you can define a a new Type for inputs so you replace thr following | |
# lines by something like this: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# db/seeds.rb | |
Book.create( | |
title: "A brief History of Time", | |
author: "Stephen Hawking", | |
review: "A very informative book from an insiders perspective in the language of an outsider", | |
reviewer: "John Doe" | |
) | |
Book.create( | |
title: "Unbowed", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app/graphql/types/query_type.rb | |
module Types | |
class QueryType < Types::BaseObject | |
field :all_books, [BookType], null: true, description: "Returns a list of all Books" | |
field :book, BookType, null: true do | |
description "Returns book given an ID" | |
argument :id, ID, required: true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/graphql/types/book_type.rb | |
module Types | |
class BookType < Types::BaseObject | |
graphql_name 'BookType' | |
field :id, ID, null: false | |
field :title, String, null: false | |
field :author, String, null: true | |
field :review, String, null: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/views/layouts/application.html.erb | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>RailsReactGraphql</title> | |
<%= csrf_meta_tags %> | |
<%= csp_meta_tag %> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/views/index/index.html.erb | |
<%= javascript_pack_tag 'front-end-react/App' %> | |
<%= stylesheet_pack_tag 'front-end-react/assets/stylesheets/App' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//app/javascript/packs/front-end-react/App.jsx | |
import React, { Component } from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { ApolloProvider } from "react-apollo" | |
import { client } from "./apollo" | |
import Book from './src/bookComponent'; | |
class App extends Component { | |
render() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jkjkj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import configparser | |
import os | |
class CustomEnvInterpolation(configparser.BasicInterpolation): | |
"""Interpolation which expands environment variables in values.""" | |
def before_get(self, parser, section, option, value, defaults): | |
super().before_get(parser, section, option, value, defaults) | |
if not os.environ.get('MY_ENV'): |
OlderNewer