Class: Graphql::PersistedDocuments::Persister
- Inherits:
-
Object
- Object
- Graphql::PersistedDocuments::Persister
- Defined in:
- lib/graphql/persisted_documents/persister.rb
Constant Summary collapse
- InvalidDocumentError =
Class.new(StandardError)
- MissingPersistValidatedDocumentError =
Class.new(StandardError)
- ParseError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#query_string ⇒ Object
readonly
Returns the value of attribute query_string.
Instance Method Summary collapse
-
#initialize(query_string) ⇒ Persister
constructor
A new instance of Persister.
- #persist ⇒ Object
Constructor Details
#initialize(query_string) ⇒ Persister
Returns a new instance of Persister.
10 11 12 13 |
# File 'lib/graphql/persisted_documents/persister.rb', line 10 def initialize(query_string) @query_string = query_string @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/graphql/persisted_documents/persister.rb', line 8 def errors @errors end |
#query_string ⇒ Object (readonly)
Returns the value of attribute query_string.
8 9 10 |
# File 'lib/graphql/persisted_documents/persister.rb', line 8 def query_string @query_string end |
Instance Method Details
#persist ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/graphql/persisted_documents/persister.rb', line 15 def persist document = GraphQL.parse(query_string) query = GraphQL::Query.new(config.schema, document: document) perform_validation(query) raise InvalidDocumentError unless errors.empty? user_persister = config.persist_validated_document return user_persister.call(document) if user_persister raise MissingPersistValidatedDocumentError rescue GraphQL::ParseError raise ParseError end |