Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: deno-libs/graphql_tag
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.1.1
Choose a base ref
...
head repository: deno-libs/graphql_tag
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 3 commits
  • 9 files changed
  • 3 contributors

Commits on Mar 7, 2023

  1. add lockfile

    v1rtl committed Mar 7, 2023
    Copy the full SHA
    b5f7eb3 View commit details

Commits on Apr 23, 2023

  1. lock graphql version

    v1rtl committed Apr 23, 2023
    Copy the full SHA
    d2892e5 View commit details

Commits on Nov 9, 2023

  1. bump graphql to 16.8.1 and improve types

    talentlessguy committed Nov 9, 2023
    Copy the full SHA
    70d96ea View commit details
Showing with 72 additions and 78 deletions.
  1. +2 −2 .github/workflows/main.yml
  2. +1 −0 .gitignore
  3. +2 −2 README.md
  4. +7 −26 deno.json
  5. +29 −0 deno.lock
  6. +2 −2 deps.ts
  7. +2 −1 example.ts
  8. +24 −42 mod.ts
  9. +3 −3 mod_test.ts
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -17,9 +17,9 @@ jobs:
with:
deno-version: v1.x
- name: Run tests
run: deno test --unstable --coverage=coverage
run: deno task test
- name: Create coverage report
run: deno --unstable coverage ./coverage --lcov > coverage.lcov
run: deno task cov
- name: Collect coverage
uses: codecov/codecov-action@v1.5.0
with:
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage*
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# graphql-tag

[![GitHub release (latest by date)][releases]][releases-page] [![GitHub Workflow Status][gh-actions-img]][github-actions]
[![Codecov][codecov-badge]][codecov] [![][docs-badge]][docs]
[![GitHub release (latest by date)][releases]][releases-page]
[![GitHub Workflow Status][gh-actions-img]][github-actions] [![Codecov][codecov-badge]][codecov] [![][docs-badge]][docs]

> 🦕 Deno port of [graphql-tag](https://github.com/apollographql/graphql-tag) library.
33 changes: 7 additions & 26 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
{
"lint": {
"files": {
"include": ["./**/*.ts"],
"exclude": ["./**/*.js"]
}
"include": ["./**/*.ts"],
"exclude": ["./**/*.js"]
},
"fmt": {
"files": {
"include": ["./**/*.ts", "./**/*.md", "./**/*.json"],
"exclude": ["./**/*.js"]
},
"options": {
"singleQuote": true,
"semiColons": false,
"useTabs": false,
"indentWidth": 2,
"lineWidth": 120
}
},
"imports": {
"solc": "./mod.ts",
"solc/download": "./download.ts",
"solc/types": "./types.ts",
"solc/env": "./env.ts"
},
"test": {
"files": {
"exclude": ["./**/*.js", "examples"]
}
"singleQuote": true,
"semiColons": false,
"useTabs": false,
"indentWidth": 2,
"lineWidth": 120
},
"tasks": {
"test": "deno test --no-check --allow-net --allow-read --allow-write --coverage=coverage",
29 changes: 29 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { parse } from 'https://esm.sh/graphql@16.6.0/language/parser'
export type { DefinitionNode, DocumentNode, Location } from 'https://esm.sh/graphql@16.6.0/language/ast'
export { parse } from 'https://esm.sh/graphql@16.8.1/language/parser#='
export type { DefinitionNode, DocumentNode, Location } from 'https://esm.sh/graphql@16.8.1/language/ast#='
3 changes: 2 additions & 1 deletion example.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { buildASTSchema, graphql } from 'https://esm.sh/graphql@16.6.0'
import { graphql } from 'https://esm.sh/graphql@16.8.1#='
import { buildASTSchema } from 'https://esm.sh/graphql@16.8.1/utilities#='
import { gql } from './mod.ts'

const typeDefs = gql`
66 changes: 24 additions & 42 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { DefinitionNode, DocumentNode, Location, parse } from './deps.ts'
import { parse } from './deps.ts'

import type { DefinitionNode, DocumentNode, Location } from './deps.ts'

// A map docString -> graphql document
const docCache = new Map<string, DocumentNode>()

@@ -37,15 +40,13 @@ function processFragments(ast: DocumentNode) {
// the same name as one previously registered. So, we tell them about it.
if (printFragmentWarnings) {
console.warn(
'Warning: fragment with name ' +
fragmentName +
' already exists.\n' +
'Warning: fragment with name ' + fragmentName + ' already exists.\n' +
'graphql-tag enforces all fragment names across your application to be unique; read more about\n' +
'this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names'
'this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names',
)
}
} else if (!sourceKeySet) {
fragmentSourceMap.set(fragmentName, (sourceKeySet = new Set()))
fragmentSourceMap.set(fragmentName, sourceKeySet = new Set())
}

sourceKeySet.add(sourceKey)
@@ -61,37 +62,37 @@ function processFragments(ast: DocumentNode) {

return {
...ast,
definitions
definitions,
}
}

function stripLoc(doc: DocumentNode) {
const workSet = new Set<Record<string, any>>(doc.definitions)
const workSet = new Set<DefinitionNode>(doc.definitions)

workSet.forEach((node) => {
if (node.loc) delete node.loc
if (node.loc) Reflect.deleteProperty(node, 'loc')
Object.keys(node).forEach((key) => {
const value = node[key]
const value = node[key as keyof DefinitionNode]
if (value && typeof value === 'object') {
workSet.add(value)
workSet.add(value as unknown as DefinitionNode)
}
})
})

const loc = doc.loc as { startToken: unknown; endToken: unknown }
const loc = doc.loc
if (loc) {
delete loc.startToken
delete loc.endToken
Reflect.deleteProperty(loc, 'startToken');
Reflect.deleteProperty(loc, 'endToken');
}

return doc
}

function parseDocument(source: string) {
var cacheKey = normalize(source)
const cacheKey = normalize(source)
if (!docCache.has(cacheKey)) {
const parsed = parse(source, {
allowLegacyFragmentVariables
allowLegacyFragmentVariables,
})
if (!parsed || parsed.kind !== 'Document') {
throw new Error('Not a valid GraphQL document.')
@@ -100,36 +101,17 @@ function parseDocument(source: string) {
cacheKey,
// check that all "new" fragments inside the documents are consistent with
// existing fragments of the same name
stripLoc(processFragments(parsed))
stripLoc(processFragments(parsed)),
)
}
return docCache.get(cacheKey)!
}

/**
* Create a GraphQL AST from template literal
* @param literals
* @param args
*
* @example
* ```ts
* import { buildASTSchema, graphql } from 'https://deno.land/x/graphql_deno@v15.0.0/mod.ts'
* import { gql } from 'https://deno.land/x/graphql_tag/mod.ts'
*
* const typeDefs = gql`
* type Query {
* hello: String
* }
* `
*
* const query = `{ hello }`
*
* const resolvers = { hello: () => 'world' }
*
* console.log(await graphql(buildASTSchema(typeDefs), query, resolvers))
* ```
*/
export function gql(literals: string | readonly string[], ...args: any[]) {
// XXX This should eventually disallow arbitrary string interpolation, like Relay does
export function gql(
literals: string | readonly string[],
...args: DocumentNode[]
) {
if (typeof literals === 'string') {
literals = [literals]
}
@@ -138,7 +120,7 @@ export function gql(literals: string | readonly string[], ...args: any[]) {

args.forEach((arg, i) => {
if (arg && arg.kind === 'Document') {
result += arg.loc.source.body
result += arg.loc!.source.body
} else {
result += arg
}
6 changes: 3 additions & 3 deletions mod_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { buildASTSchema, isSchema } from 'https://esm.sh/graphql@16.6.0'
import { expect, it, run } from 'https://deno.land/x/tincan@1.0.1/mod.ts'
import { buildASTSchema } from 'https://esm.sh/graphql@16.6.0/utilities#='
import { expect, it, run } from 'https://deno.land/x/tincan@1.0.2/mod.ts'
import { gql } from './mod.ts'

const typeDefs = gql`
@@ -15,7 +15,7 @@ it('Returns a valid document node', () => {
it('Creates a valid schema from AST', () => {
const schema = buildASTSchema(typeDefs)

expect(isSchema(schema)).toBe(true)
expect(typeof schema === 'object').toBe(true)
})

run()