#NEWLINE# def is_valid_literal_value( type , value_ast ) : #NEWLINE# #INDENT# if isinstance ( type , GraphQLNonNull ) : #NEWLINE# #INDENT# of_type = type . of_type #NEWLINE# if ( not value_ast ) : #NEWLINE# #INDENT# return [ 'Expected "{}", found null.' . format ( type ) ] #NEWLINE# #UNINDENT# return is_valid_literal_value ( of_type , value_ast ) #NEWLINE# #UNINDENT# if ( not value_ast ) : #NEWLINE# #INDENT# return _empty_list #NEWLINE# #UNINDENT# if isinstance ( value_ast , ast . Variable ) : #NEWLINE# #INDENT# return _empty_list #NEWLINE# #UNINDENT# if isinstance ( type , GraphQLList ) : #NEWLINE# #INDENT# item_type = type . of_type #NEWLINE# if isinstance ( value_ast , ast . ListValue ) : #NEWLINE# #INDENT# errors = [ ] #NEWLINE# for ( i , item_ast ) in enumerate ( value_ast . values ) : #NEWLINE# #INDENT# item_errors = is_valid_literal_value ( item_type , item_ast ) #NEWLINE# for error in item_errors : #NEWLINE# #INDENT# errors . append ( 'In element #{}: {}' . format ( i , error ) ) #NEWLINE# #UNINDENT# #UNINDENT# return errors #NEWLINE# #UNINDENT# return is_valid_literal_value ( item_type , value_ast ) #NEWLINE# #UNINDENT# if isinstance ( type , GraphQLInputObjectType ) : #NEWLINE# #INDENT# if ( not isinstance ( value_ast , ast . ObjectValue ) ) : #NEWLINE# #INDENT# return [ 'Expected "{}", found not an object.' . format ( type ) ] #NEWLINE# #UNINDENT# fields = type . get_fields ( ) #NEWLINE# field_asts = value_ast . fields #NEWLINE# errors = [ ] #NEWLINE# for provided_field_ast in field_asts : #NEWLINE# #INDENT# if ( provided_field_ast . name . value not in fields ) : #NEWLINE# #INDENT# errors . append ( 'In field "{}": Unknown field.' . format ( provided_field_ast . name . value ) ) #NEWLINE# #UNINDENT# #UNINDENT# field_ast_map = { field_ast . name . value : field_ast for field_ast in field_asts } #NEWLINE# def get_field_ast_value( field_name ) : #NEWLINE# #INDENT# if ( field_name in field_ast_map ) : #NEWLINE# #INDENT# return field_ast_map [ field_name ] . value #NEWLINE# #UNINDENT# #UNINDENT# for ( field_name , field ) in fields . items ( ) : #NEWLINE# #INDENT# subfield_errors = is_valid_literal_value ( field . type , get_field_ast_value ( field_name ) ) #NEWLINE# errors . extend ( ( 'In field "{}": {}' . format ( i , e ) for e in subfield_errors ) ) #NEWLINE# #UNINDENT# return errors #NEWLINE# #UNINDENT# assert isinstance ( type , ( GraphQLScalarType , GraphQLEnumType ) ) , 'Must be input type' #NEWLINE# parse_result = type . parse_literal ( value_ast ) #NEWLINE# if ( parse_result is None ) : #NEWLINE# #INDENT# return [ 'Expected type "{}", found {}.' . format ( type . name , print_ast ( value_ast ) ) ] #NEWLINE# #UNINDENT# return _empty_list