1# Copyright (c) 2015-present, Facebook, Inc. 2# 3# This source code is licensed under the MIT license found in the 4# LICENSE file in the root directory of this source tree. 5 6from __future__ import print_function 7class Printer(object): 8 def __init__(self): 9 pass 10 11 def start_file(self): 12 print('''/* @flow */ 13/* @generated */ 14/* jshint ignore:start */ 15 16/** 17 * Copyright (c) 2015-present, Facebook, Inc. 18 * 19 * This source code is licensed under the MIT license found in the 20 * LICENSE file in the root directory of this source tree. 21 */ 22 23type Node = { 24 kind: string; 25 start?: ?number; 26 end?: ?number; 27}; 28 29type OperationKind = 'query' | 'mutation' | 'subscription';''') 30 31 def end_file(self): 32 pass 33 34 def start_type(self, name): 35 print() 36 print('type %s = Node & {' % name) 37 kind = name 38 if kind == 'GenericType': 39 kind = 'Type' 40 print(' kind: \'%s\';' % kind) 41 42 def end_type(self, name): 43 print('}') 44 45 def _js_type(self, type, plural): 46 if plural: 47 type = 'Array<%s>' % type 48 return type 49 50 def field(self, type, name, nullable, plural): 51 nullable_char = '?' if nullable else '' 52 js_type = self._js_type(type, plural) 53 print(' %(name)s%(nullable_char)s: %(nullable_char)s%(js_type)s;' % locals()) 54 55 def start_union(self, name): 56 print(('type %s = ' % name), end=' ') 57 self._current_options = [] 58 59 def union_option(self, type): 60 self._current_options.append(type) 61 62 def end_union(self, name): 63 print('\n | '.join(self._current_options)) 64 print() 65 self._current_options = None 66