0

In all the graphql literature the recommended way of creating a graphql type is like so:

import {gql} from 'graphql-tag'
const query = const typeDefs = gql`

type Book {
  title: String
  author: String
}

# The "Query" type is the root of all GraphQL queries.

type Query {
  books: [Book]
}

`;

I have never seen an argument passed to a function without parenthesis in javascript before now so I did some tests

const fn = (n) => n+1

// pass a number

fn1; // Reference error can't find fn1

// Pass a string

fn'1' // Syntax error Unexpected string literal '1'

// Pass a template

fn`1` // => "11"

What sort of black magic is happening in the engine that makes this possible with template strings? I'm guessing it has to do with how template strings are interpreted by the js engine, presumably wrapping them implicitly in parenthesis, but I don't know.

richbai90
  • 4,994
  • 4
  • 50
  • 85
  • 1
    [tagged templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates) – Pointy Nov 14 '18 at 17:33
  • a function followed by a template literal calls the function and passes in the literal splitted up into chunks – Jonas Wilms Nov 14 '18 at 17:36

0 Answers0