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