# frozen_string_literal: true require_relative "../test_helper" module Parser class GraphQLTest < Minitest::Spec include SnapshotUtils test "graphql tag" do assert_parsed_snapshot(<<~HTML, erb_openers: ["graphql"]) <%graphql fragment HumanFragment on Human { name homePlanet } %> HTML end test "graphql tag with comment and html" do assert_parsed_snapshot(<<~HTML, erb_openers: ["graphql"]) <%# app/views/humans/human.html.erb %> <%graphql fragment HumanFragment on Human { name homePlanet } %>
<%= human.name %> lives on <%= human.home_planet %>.
HTML end test "graphql tag inline" do assert_parsed_snapshot(%(<%graphql query { users { id } } %>), erb_openers: ["graphql"]) end test "graphql tag with query variables" do assert_parsed_snapshot(<<~HTML, erb_openers: ["graphql"]) <%graphql query Products($first: Int!) { products(first: $first) { nodes { id title } } } %> HTML end test "erb tag with graphql variable is not a graphql tag" do assert_parsed_snapshot(%(<% graphql = "query" %>), erb_openers: ["graphql"]) end test "erb tag calling a method starting with graphql is not a graphql tag" do assert_parsed_snapshot(%(<%graphql_helper %>), erb_openers: ["graphql"]) end test "erb tag whose code starts with the letters graphql is not a graphql tag" do assert_parsed_snapshot(%(<%graphqlish %>), erb_openers: ["graphql"]) end end end